Jump to content

Recommended Posts

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!

Link to comment
https://forums.phpfreaks.com/topic/225789-php-script-that-run-other-php-scripts/
Share on other sites

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

 

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.

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

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';

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.