...

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



SystemJay
10-12-2009, 11:49 AM
Alright..

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.




$secondrunner=0;
while($secondrunner < 3) {

include("runthis.php");

$secondrunner+=1;
//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 =)

SKDevelopment
10-12-2009, 12: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.

SystemJay
10-12-2009, 04: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.
:thumbsup:



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum