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.

Post New Thread Reply

Register GFY Rules Calendar
Go Back   GoFuckYourself.com - Adult Webmaster Forum > >
Discuss what's fucking going on, and which programs are best and worst. One-time "program" announcements from "established" webmasters are allowed.

 
Thread Tools
Old 05-13-2012, 06:22 AM   #1
roly
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
roly is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 05-13-2012, 06:25 AM   #2
V_RocKs
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.
V_RocKs is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 05-13-2012, 06:26 AM   #3
Babaganoosh
♥♥♥ Likes Hugs ♥♥♥
 
Babaganoosh's Avatar
 
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.
Babaganoosh is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 05-13-2012, 06:34 AM   #4
EddyTheDog
Just Doing My Own Thing
 
EddyTheDog's Avatar
 
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.
EddyTheDog is online now   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 05-13-2012, 06:52 AM   #5
asdasd
So Fucking Banned
 
Industry Role:
Join Date: Feb 2005
Posts: 1,225
Call Microsoft !!!
asdasd is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 05-13-2012, 08:26 AM   #6
SmokeyTheBear
►SouthOfHeaven
 
SmokeyTheBear's Avatar
 
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
SmokeyTheBear is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 05-13-2012, 09:50 AM   #7
potter
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.
__________________

potter is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 05-13-2012, 09:53 AM   #8
Babaganoosh
♥♥♥ Likes Hugs ♥♥♥
 
Babaganoosh's Avatar
 
Industry Role:
Join Date: Nov 2001
Location: /home
Posts: 15,841
Quote:
Originally Posted by potter View Post
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.
Unnecessary db call is unnecessary.
__________________
I like pie.
Babaganoosh is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 05-13-2012, 10:27 AM   #9
HomerSimpson
Too lazy to set a custom title
 
HomerSimpson's Avatar
 
Industry Role:
Join Date: Sep 2005
Location: Springfield
Posts: 13,826
http://www.awmzone.com/services
__________________
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:
HomerSimpson is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 05-13-2012, 10:31 AM   #10
potter
Confirmed User
 
Industry Role:
Join Date: Dec 2004
Location: Denver
Posts: 6,559
Quote:
Originally Posted by Babaganoosh View Post
Unnecessary db call is unnecessary.
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.
__________________

potter is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 05-13-2012, 10:54 AM   #11
Babaganoosh
♥♥♥ Likes Hugs ♥♥♥
 
Babaganoosh's Avatar
 
Industry Role:
Join Date: Nov 2001
Location: /home
Posts: 15,841
Quote:
Originally Posted by potter View Post
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.
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.
Babaganoosh is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 05-13-2012, 11:13 AM   #12
fris
Too lazy to set a custom title
 
fris's Avatar
 
Industry Role:
Join Date: Aug 2002
Posts: 55,359
Quote:
Originally Posted by roly View Post
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
i did something like this, i had 30 links, which would rotate one spot per day, so everyone got the same exposure.

not sure if that interests you.
__________________
Since 1999: 69 Adult Industry awards for Best Hosting Company and professional excellence.


WP Stuff
fris is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 05-13-2012, 11:24 AM   #13
roly
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'];
}
i want to copy the output of that into a text file as discussed so that i can include it in a file, how do i do that? fopen? any idea how i would write it?

Last edited by roly; 05-13-2012 at 11:25 AM..
roly is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 05-13-2012, 11:26 AM   #14
Babaganoosh
♥♥♥ Likes Hugs ♥♥♥
 
Babaganoosh's Avatar
 
Industry Role:
Join Date: Nov 2001
Location: /home
Posts: 15,841
Quote:
Originally Posted by roly View Post
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'];
}
i want to copy the output of that into a text file as discussed so that i can include it in a file, how do i do that? fopen? any idea how i would write it?
http://php.net/manual/en/function.fwrite.php
__________________
I like pie.
Babaganoosh is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 05-13-2012, 11:27 AM   #15
roly
Confirmed User
 
Join Date: Aug 2002
Posts: 1,844
Quote:
Originally Posted by SmokeyTheBear View Post
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
well the bulk of the page is generated on the fly and with almost the whole page content changing with every refresh i think that's likely to look spammy with google. i would rather google think it was a static page that was updated daily.
roly is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 05-13-2012, 11:28 AM   #16
roly
Confirmed User
 
Join Date: Aug 2002
Posts: 1,844
Quote:
Originally Posted by fris View Post
i did something like this, i had 30 links, which would rotate one spot per day, so everyone got the same exposure.

not sure if that interests you.
yes that's the sort of thing.
roly is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 05-13-2012, 11:29 AM   #17
roly
Confirmed User
 
Join Date: Aug 2002
Posts: 1,844
Quote:
Originally Posted by Babaganoosh View Post
that looks like what i'm looking for thanks
roly is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 05-13-2012, 11:41 AM   #18
fris
Too lazy to set a custom title
 
fris's Avatar
 
Industry Role:
Join Date: Aug 2002
Posts: 55,359
Quote:
Originally Posted by roly View Post
yes that's the sort of thing.
links.txt

Code:
http://www.bing.com|very unpopular search engine
http://www.google.com|search engine
http://www.gfy.com|gfy forum
to show the links

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];
}
	
?>
script to run in crontab once every 24 hours

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
fris is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 05-13-2012, 01:39 PM   #19
roly
Confirmed User
 
Join Date: Aug 2002
Posts: 1,844
thanks fris that's a big help
roly is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 05-14-2012, 10:03 AM   #20
roly
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'];
}
into this $scriptoutput:

Code:
$myfile= fopen ("/home/domains/domain.com/public_html/mytxt.txt", "w+");
fwrite($myfile, $scriptoutput);
fclose($myfile;
how do i get that first little script to output into $scriptoutput, that's what i'm stuck on, anyone got any advice?

thanks in advance

Last edited by roly; 05-14-2012 at 10:12 AM..
roly is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 05-14-2012, 11:03 AM   #21
Brujah
Beer Money Baron
 
Brujah's Avatar
 
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;
If you're interested in using prepared statements, you can do this:
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 );
set up a cron to execute this every 24 hours
0 3 * * * /usr/bin/php /path/to/cron.php
__________________

Last edited by Brujah; 05-14-2012 at 11:05 AM..
Brujah is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 05-14-2012, 11:47 AM   #22
roly
Confirmed User
 
Join Date: Aug 2002
Posts: 1,844
Quote:
Originally Posted by Brujah View Post
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;
If you're interested in using prepared statements, you can do this:
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 );
set up a cron to execute this every 24 hours
0 3 * * * /usr/bin/php /path/to/cron.php
Thanks Brujah, that's a big help, very much appreciated.
roly is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 05-14-2012, 11:54 AM   #23
Brujah
Beer Money Baron
 
Brujah's Avatar
 
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' ); ?>
__________________
Brujah is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 05-14-2012, 12:28 PM   #24
xJerk
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
xJerk is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 05-14-2012, 01:18 PM   #25
roly
Confirmed User
 
Join Date: Aug 2002
Posts: 1,844
Quote:
Originally Posted by Brujah View Post
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' ); ?>
i'm using
Quote:
<?php include ("/home/domain.com/public_html/saved.txt"); ?>
is that just as efficient?

it's all working perfectly thanks
roly is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 05-14-2012, 01:19 PM   #26
roly
Confirmed User
 
Join Date: Aug 2002
Posts: 1,844
Quote:
Originally Posted by xJerk View Post
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).
got it sorted thanks, but that's a new one i've never heard of which i'm sure will have its uses.
roly is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 05-14-2012, 01:53 PM   #27
Brujah
Beer Money Baron
 
Brujah's Avatar
 
Industry Role:
Join Date: Jan 2001
Location: brujah / gmail
Posts: 22,157
Quote:
Originally Posted by roly View Post
i'm using


is that just as efficient?

it's all working perfectly thanks
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.
__________________
Brujah is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 05-15-2012, 05:05 AM   #28
roly
Confirmed User
 
Join Date: Aug 2002
Posts: 1,844
Quote:
Originally Posted by Brujah View Post
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.
that's great, thanks again
roly is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 05-16-2012, 10:20 AM   #29
potter
Confirmed User
 
Industry Role:
Join Date: Dec 2004
Location: Denver
Posts: 6,559
Quote:
Originally Posted by Babaganoosh View Post
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.
Your idea breaks down if the file is ever manually updated, or if there isn't actually a static file to update and it's a dynamic page.

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.
__________________

potter is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Post New Thread Reply
Go Back   GoFuckYourself.com - Adult Webmaster Forum > >

Bookmarks



Advertising inquiries - marketing at gfy dot com

Contact Admin - Advertise - GFY Rules - Top

©2000-, AI Media Network Inc



Powered by vBulletin
Copyright © 2000- Jelsoft Enterprises Limited.