![]() |
![]() |
![]() |
||||
Welcome to the GoFuckYourself.com - Adult Webmaster Forum forums. You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today! If you have any problems with the registration process or your account login, please contact us. |
![]() ![]() |
|
Discuss what's fucking going on, and which programs are best and worst. One-time "program" announcements from "established" webmasters are allowed. |
|
Thread Tools |
![]() |
#1 |
Confirmed User
Join Date: Aug 2002
Posts: 1,844
|
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 |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#2 |
Damn Right I Kiss Ass!
Industry Role:
Join Date: Dec 2003
Location: Cowtown, USA
Posts: 32,409
|
Best to do exactly what you already suggested.
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#3 |
♥♥♥ Likes Hugs ♥♥♥
Industry Role:
Join Date: Nov 2001
Location: /home
Posts: 15,841
|
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.
__________________
I like pie. |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#4 |
Just Doing My Own Thing
Industry Role:
Join Date: Jan 2011
Location: London, Spain, New Zealand, GFY - Not Croydon...
Posts: 25,064
|
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.
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#5 |
So Fucking Banned
Industry Role:
Join Date: Feb 2005
Posts: 1,225
|
Call Microsoft !!!
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#6 |
►SouthOfHeaven
Join Date: Jun 2004
Location: PlanetEarth MyBoardRank: GerbilMaster My-Penis-Size: extralarge MyWeapon: Computer
Posts: 28,609
|
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
__________________
hatisblack at yahoo.com |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#7 |
Confirmed User
Industry Role:
Join Date: Dec 2004
Location: Denver
Posts: 6,559
|
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.
__________________
![]() |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#8 | |
♥♥♥ Likes Hugs ♥♥♥
Industry Role:
Join Date: Nov 2001
Location: /home
Posts: 15,841
|
Quote:
__________________
I like pie. |
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#9 |
Too lazy to set a custom title
Industry Role:
Join Date: Sep 2005
Location: Springfield
Posts: 13,826
|
__________________
Make a bank with Chaturbate - the best selling webcam program ![]() ![]() ![]() Ads that can't be block with AdBlockers !!! /// Best paying popup program (Bitcoin payouts) !!! PHP, MySql, Smarty, CodeIgniter, Laravel, WordPress, NATS... fixing stuff, server migrations & optimizations... My ICQ: 27429884 | Email: ![]() |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#10 |
Confirmed User
Industry Role:
Join Date: Dec 2004
Location: Denver
Posts: 6,559
|
Well, as stated already a cron job be the best way.
But please don't try to make it out like a single db query to get a single field value is bad. ![]()
__________________
![]() |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#11 |
♥♥♥ Likes Hugs ♥♥♥
Industry Role:
Join Date: Nov 2001
Location: /home
Posts: 15,841
|
Not trying to make a big deal out of it but if a file is written there's already a timestamp. There's no reason to make an entry in a db and query the db every time we want to see when the file was created. That step is completely redundant.
__________________
I like pie. |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#12 | |
Too lazy to set a custom title
Industry Role:
Join Date: Aug 2002
Posts: 55,359
|
Quote:
not sure if that interests you.
__________________
Since 1999: 69 Adult Industry awards for Best Hosting Company and professional excellence. ![]() WP Stuff |
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#13 |
Confirmed User
Join Date: Aug 2002
Posts: 1,844
|
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"; $result = mysql_query($sql ,$db); while ($myrow = mysql_fetch_array($result)) { echo $myrow['something']; } |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#14 | |
♥♥♥ Likes Hugs ♥♥♥
Industry Role:
Join Date: Nov 2001
Location: /home
Posts: 15,841
|
Quote:
__________________
I like pie. |
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#15 | |
Confirmed User
Join Date: Aug 2002
Posts: 1,844
|
Quote:
|
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#16 |
Confirmed User
Join Date: Aug 2002
Posts: 1,844
|
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#17 | |
Confirmed User
Join Date: Aug 2002
Posts: 1,844
|
Quote:
|
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#18 |
Too lazy to set a custom title
Industry Role:
Join Date: Aug 2002
Posts: 55,359
|
links.txt
Code:
http://www.bing.com|very unpopular search engine http://www.google.com|search engine http://www.gfy.com|gfy forum Code:
<? $show = 30; $linkfile = dirname(__FILE__). "/links.txt"; $links = file($linkfile); $result = array(); for ($i=0; (($i<$show) && ($i<count($links))); $i++) { $link = explode("|", $links[$i]); $result[] = '<a href="' . $link[0] . '">' . $link[1] . '</a><br/>'; echo $result[$i]; } ?> Code:
<? $linkfile = dirname(__FILE__). "/links.txt"; $tmp = file($linkfile); $result = array(); $result[] = trim($tmp[(count($tmp)-1)]); unset($tmp[(count($tmp)-1)]); foreach ($tmp as $idx => $t) { $result[] = trim($t); } $s = implode("\n", $result); $fp = fopen($linkfile, "w+"); fwrite($fp, $s); fclose($fp); ?>
__________________
Since 1999: 69 Adult Industry awards for Best Hosting Company and professional excellence. ![]() WP Stuff |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#19 |
Confirmed User
Join Date: Aug 2002
Posts: 1,844
|
thanks fris that's a big help
![]() |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#20 |
Confirmed User
Join Date: Aug 2002
Posts: 1,844
|
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"; $result = mysql_query($sql ,$db); while ($myrow = mysql_fetch_array($result)) { echo $myrow['something']; } Code:
$myfile= fopen ("/home/domains/domain.com/public_html/mytxt.txt", "w+"); fwrite($myfile, $scriptoutput); fclose($myfile; thanks in advance |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#21 |
Beer Money Baron
Industry Role:
Join Date: Jan 2001
Location: brujah / gmail
Posts: 22,157
|
Code:
$sql = "select foo from bar where catid = $cat limit 20"; $result = mysql_query($sql ,$db); $scriptoutput = ''; while ($myrow = mysql_fetch_array($result)) { $scriptoutput .= '<li>' . $myrow['something']; } $myfile= fopen ("/home/domains/domain.com/public_html/mytxt.txt", "w+"); fwrite($myfile, $scriptoutput); fclose($myfile; Code:
$mysqli = new mysql( 'localhost', 'username', 'password', 'db' ); $content = ''; if( $stmt = $mysqli->prepare("SELECT foo FROM bar WHERE catid = ? LIMIT 20") ) { $stmt->bind_param( 'i', $cat ); $stmt->execute(); $stmt->bind_result( $foo ); while ( $stmt->fetch() ) { $content .= '<li>' . $foo; } $stmt->close(); } $mysqli->close(); file_put_contents( '/path/to/saved.txt', $content ); 0 3 * * * /usr/bin/php /path/to/cron.php
__________________
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#22 | |
Confirmed User
Join Date: Aug 2002
Posts: 1,844
|
Quote:
![]() |
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#23 |
Beer Money Baron
Industry Role:
Join Date: Jan 2001
Location: brujah / gmail
Posts: 22,157
|
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' ); ?>
__________________
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#24 |
Registered User
Industry Role:
Join Date: Jun 2011
Posts: 33
|
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).
__________________
Contact: admin [at] xjerk.com |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#25 | ||
Confirmed User
Join Date: Aug 2002
Posts: 1,844
|
Quote:
Quote:
it's all working perfectly thanks |
||
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#26 |
Confirmed User
Join Date: Aug 2002
Posts: 1,844
|
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#27 |
Beer Money Baron
Industry Role:
Join Date: Jan 2001
Location: brujah / gmail
Posts: 22,157
|
I prefer file_get_contents() in this case, and it's probably safer just in case, since it won't attempt to execute code or anything.
__________________
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#28 |
Confirmed User
Join Date: Aug 2002
Posts: 1,844
|
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#29 | |
Confirmed User
Industry Role:
Join Date: Dec 2004
Location: Denver
Posts: 6,559
|
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.
__________________
![]() |
|
![]() |
![]() ![]() ![]() ![]() ![]() |