Reply to Re: Newbie needs a workaround - No Cron Jobs on Godaddy shared server!

Your name:

Reply:


Posted by Ciaran on 01/30/06 11:53

Rob, you could try something like the below.

Basically it checks the logfile's modified date, which should be
cheaper than opening it. Also you can set a probability that a page
will trigger a DB check, to avoid multiple pages trying to do the check
at the same time.

It includes a mechanism for locking, so that hopefully if a number of
scripts are all checking the log at the same time, the later ones will
fail.

Note: this is just to give you an idea, I haven't tested this:

<?php

$logfile = 'test.txt'; // the file to write to
$timeout = 60*60*24; // set timeout to an hour
$prob = 1000; // the probability a script will bother checking

// only do the check one time in $prob times!
if(rand(1, $prob) == 1){


// only do this if the file isn't there or its modified time
// is longer ago than the timeout
if(!file_exists($logfile) || (time() - filemtime($logfile)) >
$timeout){

// open the file for appending
$fp = fopen($logfile, "a");

// ask for an exclusive lock
if (flock($fp, LOCK_EX)) {

// do whatever checks you want, here!

// write to the log
fwrite($fp, "Completed DB Check at ".date('Y-m-d H:i:s')."\n");

// release the lock
flock($fp, LOCK_UN);

} else {

// if you couldn't lock it, error!
echo "<!-- DB check failed -->";
}

// close the file pointer
fclose($fp);

}

}

?>

-Ciaran



-Ciaran

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация