Page 1 of 1

How do you run one php script from another

Posted: Mon Sep 29, 2008 5:02 am
by edzillion
I am pretty sure this is not possible, but I can't find anything about it.
I have a *lot* of cron jobs that I need to schedule to run v. often (every min) and instead of adding all of them to the cron job list, I thought instead that I could add one php script that would then call all the various scripts and log errors etc.

So is it possible to call a php script from another php file? What are the options?

Cheers
Ed

Re: How do you run one php script from another

Posted: Mon Sep 29, 2008 5:03 am
by The_Anomaly
I'm assuming that you mean something other than the require(), require_once(), include() and include_once() functions?

Re: How do you run one php script from another

Posted: Mon Sep 29, 2008 5:12 am
by edzillion
Well what I want to do is run a number of php query strings from the 'mother' php file. e.g:

abracadabra.php?query1=start&query2=middle

etc. I dont think the include statements provide for that?

Re: How do you run one php script from another

Posted: Mon Sep 29, 2008 5:29 am
by The_Anomaly
From my understanding of what you want to do, put your GET data into an array, and loop through the array, require_once()ing the php file with the value of the querystring. It would then "process" any of the scripts with the same name as your query strings.

For example, you have two PHP files, Peanuts and Butter. You want to "process" them from the page Food.

food.php?cmd1=Peanuts&cmd2=butter

Code: Select all

 
 
$array = $_GET;
 
foreach( $array as &$value ) {
    require_once("$value.php");
}
 
Something like that might work. Of course, if this was public, you'd want to do all sorts of filtering, as they can execute any PHP file with just a query string.