The450Man Posted January 26, 2011 Share Posted January 26, 2011 First of all, im a newb when it comes to scripting other then html/xhtml/css. I need a php script that will run through a list of other php scripts and run them. These are stored on a sever inside a folder. Now the tricky thing is, i would like it to go in some kind of order. Meaning it will not repeat the same php script twice until it runs through all of the scripts. Once it has hit the last script, it starts over. The main php script will be ran by a cron so it will be automated. I tried to set up a cron on each script but it is limited funtcion wise (cant state when to start running the first instance of the cron). Make sense? All help is appreciated! Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/225789-php-script-that-run-other-php-scripts/ Share on other sites More sharing options...
Maq Posted January 26, 2011 Share Posted January 26, 2011 If you want to run them on the CLI you can use shell_exec. Quote Link to comment https://forums.phpfreaks.com/topic/225789-php-script-that-run-other-php-scripts/#findComment-1165668 Share on other sites More sharing options...
litebearer Posted January 26, 2011 Share Posted January 26, 2011 script 0 see if session job is set if not run job 1 value = 1 set session value else get value value ++ endif switch case 1 do script 1 case 2 do script 2 etc etc script 1 do whatever redirect to script 0 when done etc etc Quote Link to comment https://forums.phpfreaks.com/topic/225789-php-script-that-run-other-php-scripts/#findComment-1165670 Share on other sites More sharing options...
The450Man Posted January 28, 2011 Author Share Posted January 28, 2011 Interesting, thanks for the responses. Learning as I go allong. One other thing I should of cleared up. Im not sure if its entirely possible in php but.. When I run the main script, I want it to run the first secondary script and only that script for that instance. Then 4 hours later, a cron will run running the main script that runs the second secondary script. There are several instances of the secondary script. So first run of the main php runs the php script #1 an hour or so later The second run of the main php runs the php script #2 another hour or so later The third run of the main php runs the third php script #3 Now for times sake, this process goes on 20 times. Once it runs of of php scripts to run, it starts over starting from top to bottom again. Thanks! Ive been pulling my hair out trying to figure this out. I know its gota be confusing for you guys as I just confused myself trying to explain it. Quote Link to comment https://forums.phpfreaks.com/topic/225789-php-script-that-run-other-php-scripts/#findComment-1166762 Share on other sites More sharing options...
litebearer Posted January 29, 2011 Share Posted January 29, 2011 cron calls script 1 every hour (only 1 cron needed) script 1 says if 2AM do this, if 3AM do this, if 4AM do that Quote Link to comment https://forums.phpfreaks.com/topic/225789-php-script-that-run-other-php-scripts/#findComment-1166799 Share on other sites More sharing options...
lazylodr Posted January 29, 2011 Share Posted January 29, 2011 I believe an include will execute the script as well within the context of the including script (and you can even have a return value from the script that you included) Quote Link to comment https://forums.phpfreaks.com/topic/225789-php-script-that-run-other-php-scripts/#findComment-1166846 Share on other sites More sharing options...
The450Man Posted February 5, 2011 Author Share Posted February 5, 2011 yea, I can use the include function but it activates all of the php scripts at the same time/instance. I need each php script to run after a different instance of the php script. Quote Link to comment https://forums.phpfreaks.com/topic/225789-php-script-that-run-other-php-scripts/#findComment-1170323 Share on other sites More sharing options...
doni49 Posted February 8, 2011 Share Posted February 8, 2011 If the cron runs fileA.php and you want fileA.php to run subA.php in the first instanceand subB.php to run the second (and so on.....), then try this: [*]have fileA.php include a file called include.php (which will cause the code in that file to run--don't worry, this isn't a file you're currently using.) [*]subA.php and subB.php etc will each have a variable set that identifies which file is next [*]After include.php runs, fileA.php would copy $nextFileVar (subA.php or subB.php etc) as include.php [*]the next time fileA.php runs, it will run the next php file in the list and then copy Quote Link to comment https://forums.phpfreaks.com/topic/225789-php-script-that-run-other-php-scripts/#findComment-1171217 Share on other sites More sharing options...
doni49 Posted February 8, 2011 Share Posted February 8, 2011 I thought I'd put together a better example of what I'm suggesting. fileA.php (is run by the cron) include('include.php'); copy($nextSub, 'include.php'); subA.php //do something for the first instance $nextSub = 'subB.php'; subB.php //do something for the second instance $nextSub = 'subC.php'; subC.php //do something for the third instance $nextSub = 'subD.php'; subE.php //do something for the fourth instance $nextSub = 'subE.php'; Quote Link to comment https://forums.phpfreaks.com/topic/225789-php-script-that-run-other-php-scripts/#findComment-1171220 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.