View Full Version : Running a PHP script from a PHP script.

10-12-2009, 12:49 PM

So I tried something simple to overcome the problem that
I cannot run easly conrjob's in second on LAMP/WAMP. I created
a tiny script that would be developed futher but I came up
with a problem at the beginning.

while($secondrunner < 3) {


//sleepy here

I would call this script once a minute, but this script would call another
script more frequently than once a minute. This way I could get a cron job
to happen faster than 1 minute intervals.

problem: First run goes fine of course, but when this script would repeat itself
It cannot of course redeclare the same functions which are in the
"runthis.php" script. Fatal error: Cannot redeclare function().

How can I make the script to forget that the functions are already declared
and so to say start from an empty table? Id like to know the aswer, thanks =)

10-12-2009, 01:25 PM
You would need to declare functions in a separate script and inlcude it at the top.

runthis.php would only call these functions.

Of course you could check if a function exists with function_exists() (http://php.net/function_exists) and declare it only if it does not, but I would really strongly recommend against it.

Simply divide runthis.php into 2 scripts: with function declarations and with calls to the functions. Then include function declarations at the top and include function calls in the loop.

10-12-2009, 05:55 PM
Ah yes, quite logical =)
I was thinking that PHP would have some sort of syntax way for this,
but yes, that works quite well. Thank you for puttin my gray matter in line.