PDA

View Full Version : Execute PHP script every X seconds?


m002.p
01-16-2009, 09:49 PM
Hello everyone.

I have developed a rather complex script to query a gameserver which also makes checks on players within. However the issue I am having difficulty with is running the PHP script every X seconds.

I know of a simple way which works but doesnt seem too accurate when executing it for me.

$overall_time = 0;
while ($overall_time < 60) { $overall_time +10= ; sleep(10);

// The script

}

So I want to ask those knowledgable coders out there the best way to run a script say every 5-10 seconds using possibly a 1 min CRON kick start?

Any help appreciated.

Matt

Dismounted
01-17-2009, 10:43 AM
for ($i = 0; $i < 6; ++$i)
{
// script here
sleep(10);
}

m002.p
01-17-2009, 07:41 PM
Hi Dismounted. Out of interest is this best and most reliable way to run a script every X seconds?

Thanks for your assistance.

Dismounted
01-18-2009, 03:26 AM
Most reliable? Maybe not. The PHP script will still suffer from timeouts as defined in php.ini. The best way I can think of right now is to create a shell script that will sleep and run your PHP script (with a cron kicking it).

m002.p
01-20-2009, 09:41 PM
Any idea then how to do it with Shell?

Your help is appreciated