How do you run one php script from another

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
edzillion
Forum Newbie
Posts: 12
Joined: Mon Jan 28, 2008 10:06 am

How do you run one php script from another

Post 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
User avatar
The_Anomaly
Forum Contributor
Posts: 196
Joined: Fri Aug 08, 2008 4:56 pm
Location: Tirana, Albania

Re: How do you run one php script from another

Post by The_Anomaly »

I'm assuming that you mean something other than the require(), require_once(), include() and include_once() functions?
edzillion
Forum Newbie
Posts: 12
Joined: Mon Jan 28, 2008 10:06 am

Re: How do you run one php script from another

Post 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?
User avatar
The_Anomaly
Forum Contributor
Posts: 196
Joined: Fri Aug 08, 2008 4:56 pm
Location: Tirana, Albania

Re: How do you run one php script from another

Post 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.
Post Reply