Forum Moderators: coopster

Message Too Old, No Replies

Running a PHP file every 10 seconds on the server

php, not cron

         

nainil

4:18 am on Jun 29, 2009 (gmt 0)

10+ Year Member



Hi,

I have a PHP file which needs to be run every 10 seconds on the server. I know this has been debated as to why someone would want to do that. But I have my reasons which need me to do something which is not to the best interest of the server.

How would I do that without a cron.

-

janharders

4:51 am on Jun 29, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



maybe you could use a script that just sits somewhere and does a http request that results in running your php script, then idles for 10 seconds and repeats.

jatar_k

2:40 pm on Jun 29, 2009 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Welcome to WebmasterWorld nainil,

ho0w come without cron? cron would be the way to do it, scheduled tasks if you're on windows. Other than that it isn't really feasible to have a script that runs forever.

NomikOS

2:18 am on Jun 30, 2009 (gmt 0)

10+ Year Member



this is pure gold my man:

define a file run_at.sh

#!/bin/bash 
# change this url to automatization (need atd running)
wget [url_to_script_php_with_next_function...] > /dev/null &

and a script run_at.php with a function like:

function runNextPlease() 
{
$min = 1;
exec ("at now + $min minutes -f " . PATH_TO_BASH_SCRIPT . "run_at.sh");
}

You must investigate "at" command. I don't know if accept seconds. I don't beliebe it, but one minute is close.

[edited by: NomikOS at 2:22 am (utc) on June 30, 2009]

rocknbil

4:29 am on Jun 30, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If he can't run a cron, he's not likely to be able to run a shell script. But if that's on a remote server . . .

Perhaps you can do something by remote request where you can run a cron? Using the previous example, if your PHP script is public (accessible by the web) you can use wget or curl set in a cron to request the script remotely. The timing will be off as you'll lose seconds in making the request, but . . .

NeilsPHP

5:45 pm on Jul 1, 2009 (gmt 0)

10+ Year Member



nainil
try this little trick..

<?

$seconds = date("s", time());

echo " seconds=$seconds <br>";

$pattern = "/0\z/i";

if(preg_match($pattern, $seconds))
{

include "execute_script.php";

}
else
{
//dont execute it..do something else

}

?>