A script on a webserver should be executed once a day.
Cron-job cannot be used and it cannot be guaranteed, that the page in which the script resides is hit (at least) once a day.
So I'm trying to find a way to guarantee this daily page-hit.
Is there a web-service out there which can be subscribed and which will call a specific page once a day (checking for updates for instance)?
Any ideas that help to solve this problem are greatly apreciated.
tia
webweber
guaranteed daily page-hit
Moderator: General Moderators
Is the server Windows, thus incapable of running cron jobs? There are alternatives for windows.
If there's some bizarre complicated reason for your cron-less server, then perhaps you could have a php script running 24/7, with code somewhat like this:
Replace the /* comment with your daily code
If there's some bizarre complicated reason for your cron-less server, then perhaps you could have a php script running 24/7, with code somewhat like this:
Code: Select all
set_time_limit(0);
$seconds_per_day = 60*60*24;
while (1){
/* insert witty comment here */
sleep($seconds_per_day);
}if you cant use a cronjob (or similar) then you will need to have a date stored in a text file or a database. This date should be the last time the script was run.
then include something like
in your config file (or header or whatever) so that it gets executed on every page. That should get run once a day, tho not necessarily every 24 hours.
If you want something run at an exact time then you will be needing a cronjob type option
then include something like
Code: Select all
<?php
//get $stored_date from text file or DB
if($stored_date < intval(date('Ymd')))
{
include('cron_job_file.php');
/*
update $stored_date to date('Ymd')
*/
}
?>If you want something run at an exact time then you will be needing a cronjob type option
How would i go about making the below code execute every day? I would like a daily random flash banner (vs. every time page is refreshed):
Any suggestions?
Many thanks in advance!
Cheers
micky
Code: Select all
<?php
/* Random flash file
kvack.inc [[url]http://kvack.euphemize.net[/url]] of euphemize.net (c)MMIII
Please leave this header intact if you wish to use
*/
$directory = 'siteImages/'; //Directory relative to the file
$flashfiles = list_images($directory);
srand ((float) microtime() * 10000000);
$flash = array_rand($flashfiles);
$flash = $directory.$flash;
function list_images($path)
{
//declares $flashlist as an array. good practice.
$flashlist = array();
//$dh points to the directory object for $path.
$dh = opendir($path);
//cycle through the files/directorys in the directory object
while (false !== ($file = readdir($dh)))
//for each file/directory, if *.swf, add it to the $flashlist[] array
if (preg_match( '/\.swf$/i', $file))
{
$flashlist[] = $file;
}
//sort the list
sort($flashlist, SORT_STRING);
//returns the array.
return $flashlist;
}
function echo_result($flash)
{
echo '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="800" height="250">';
echo ' <param name="movie" value="'.$flash.'.swf"><param name="quality" value="high">';
echo ' <embed src="'.$flash.'.swf" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="800" height="250">';
echo ' </embed>';
echo '</object>';
}
/*
//Put below code where you want to include random flash banner:
<?php include($_SERVER['DOCUMENT_ROOT']."/random.php");
echo_result($flash);
*/
?>Many thanks in advance!
Cheers
micky
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
Hi Phenom, thanks for the quick response! I really appreciate it.
Your suggestion sounds great! Unfortunately, I am not familiar with using mySQL DB's... so I have to resort to a non-DB script, or possibly use a flat-file DB...
So far, this algorithm seems to be my best bet (working on the code right now):
(Using file access time:)
- first, find a file with the most recent atime
- check if(date('d', $atime) != date('d')) , choose another file
- print out the link, as browser retrieves the file, access time is updated
Hopefully that will do the trick (although, it should take me a while to integrate with current script)
Anyway, thanks again, and I am still open to suggestions. If I get it working I will post my results.
Thanks!
Cheers.
Micky
Your suggestion sounds great! Unfortunately, I am not familiar with using mySQL DB's... so I have to resort to a non-DB script, or possibly use a flat-file DB...
So far, this algorithm seems to be my best bet (working on the code right now):
(Using file access time:)
- first, find a file with the most recent atime
- check if(date('d', $atime) != date('d')) , choose another file
- print out the link, as browser retrieves the file, access time is updated
Hopefully that will do the trick (although, it should take me a while to integrate with current script)
Anyway, thanks again, and I am still open to suggestions. If I get it working I will post my results.
Thanks!
Cheers.
Micky