![]() |
quick php help required
i'm not a programmer so this might seem fairly basic stuff but here goes. i've got a dynamic page that displays random data from a mysql database. it currently displays new data with every page refresh. i'm sure google won't like this, so i want to generate the dynamic part of the page once per day (with cron?) and save it as either a txt file that i can include or use the whole original page as a template.
i know what i want to do i'm just not sure how, any suggestions of the best way of achieving this? thanks in advance |
Best to do exactly what you already suggested.
|
Set up a cron job and have it output to a static file.
Or just let the script run once normally when someone visits the page but output the content to a static file and use filemtime() to find when the file was last modified. The first solution seems easier to me but it's your call. |
You seem to have it sorted - The php just needs to get the timestamp from the txt file and if its over 24hrs old create a new one.
|
Call Microsoft !!!
|
im not sure why you think this would help. Google does check your site more than once per day but i dont think google will see much of a difference in having new data every 6 hours or every 24. It will still appear much the same to google.
Might want to set the cron a bit longer like every week or month even |
Yeah, I don't google is going to care because it's probably not checking your site more than once every 24 hours anyway. So whether you reload dynamic content every page refresh or once every 24 hours it'll likely not make a difference.
But, if you do want to continue to do what you're asking. Add a table/column/something to the database and just make it a simple unix timestamp. Everytime your page is loaded - prior to running the function that replaces the content - check whether or not time() is greater than 24 hours of the timestamp in the DB. If it isn't, you don't do anything - if it is you update the timestamp to the current time and replace the content. |
Quote:
|
|
Quote:
But please don't try to make it out like a single db query to get a single field value is bad. :2 cents: |
Quote:
|
Quote:
not sure if that interests you. |
thanks for all the replys guys, this is roughly the php code i've got
Code:
$sql = "select foo from bar where catid = $cat limit 20"; |
Quote:
|
Quote:
|
Quote:
|
Quote:
|
Quote:
Code:
http://www.bing.com|very unpopular search engine Code:
<? Code:
<? |
thanks fris that's a big help :thumbsup
|
hi
i've got the fwrite to work and my script works ok, so i've got both bits working seperately, but i'm not sure how i call all of this: Code:
$sql = "select foo from bar where catid = $cat limit 20"; Code:
$myfile= fopen ("/home/domains/domain.com/public_html/mytxt.txt", "w+"); thanks in advance |
Code:
$sql = "select foo from bar where catid = $cat limit 20"; Code:
$mysqli = new mysql( 'localhost', 'username', 'password', 'db' ); 0 3 * * * /usr/bin/php /path/to/cron.php |
Quote:
|
oops, that first line in the prepared statement should be:
$mysqli = new mysqli, forgot the i if you cron using the php /path/to/script.php example, then wherever you want it in your files you can just Code:
<?php echo file_get_contents( '/path/to/saved.txt' ); ?> |
You could do
ORDER BY RAND(CURDATE()) But there are some major performance implications with doing this with a large table (unless the query results are cached). |
Quote:
Quote:
it's all working perfectly thanks |
Quote:
|
Quote:
|
Quote:
|
Quote:
I would go as far to say a file's timestamp is akin to user input - not something I would base a script off of. |
All times are GMT -7. The time now is 07:21 PM. |
Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2025, vBulletin Solutions, Inc.
©2000-, AI Media Network Inc123