0

the situation is like this. I have created multiple php files with the name operation.php and is hosted in my domains. Something like this:

  1. example.com/operation.php
  2. example123.com/operation.php
  3. example1234.com/operation.php

Okay so now what I want is to code 1 single PHP script that will be the mother of all these operation.php scripts. Something like if I execute motherexample.com/operaterun.php from my browser then all these php scripts will run one by one.

Is this possible? Will this result in server outage? I do not want to run all these at once, maybe take a gap of 10seconds between each script execution.

Need help!

UPDATE I'm not sure whether you Guys are getting it or not but here's another example.. Let's say you have 100 sites each having maintenance.php located at example001.com/maintenance.php now it is not possible to load and run each of those 100 maintenance.php in the browser one by one. So this is why I want 1 single mother-maintenance.php that when run from the browser will execute each of those maintenance.php one by one or maybe with some time gap!

Swayam
  • 25
  • 7
  • You building a little bot net there? – Darren Nov 27 '14 at 06:39
  • @Darren lolz no! The individual php script is a maintenance script that I have to manually run for each of my websites. :-) It takes time! I want to automate the entire process! – Swayam Nov 27 '14 at 06:41
  • All good man! I'm just bored at work haha, you should be looking into what vinay posted (using `wget`) or something similar. You'll also need to prevent other people accessing it randomly – Darren Nov 27 '14 at 06:45
  • Wouldn't it be better to make a console command to do this? Doing this in a browser means you're dealing with things like browser timeout and other weird issues. – Erik Nov 27 '14 at 09:56

4 Answers4

1

If a user is doing it, I will recommend AJAX. Otherwise you can try a code like that.

<?php
$somearg = escapeshellarg('blah');
exec("php file2.php $somearg > /dev/null &");

Found on (https://stackoverflow.com/a/1110260/4268741)

However you need to make some changes to it to get it work on your project.

Community
  • 1
  • 1
IdidntKnewIt
  • 572
  • 6
  • 23
  • The other thing you can do is add `header('Location: http://example123.com/operation.php');` at the end of first operation.php file and so on. – IdidntKnewIt Nov 27 '14 at 06:47
0

You need to run something like a wget call from the mother motherexample.com/operaterun.php. wget is for linux, if you are using a windows domain check for alternatives example

wget http://example.com/operation.php
wget http://example123.com/operation.php
wget http://example1234.com/operation.php
vinay rajan
  • 351
  • 4
  • 9
0

You can use AJAX request. Just make request from your mother script to child pages.

Or you can use simple way - use iframe for each child. If you have 100 child pages then just generate on mother page 100 iframe with src to child. Or you can create this iframe by javascript and add it to page. Then you can make delay between requests.

newman
  • 2,689
  • 15
  • 23
  • Yeah! I was checking this out in Google. I can't use delay in-between iframe execution? For using iframe by javascript how do I do that? Please help.. – Swayam Nov 27 '14 at 07:00
  • @Swayam for example you can check this question http://stackoverflow.com/questions/3069915/javascript-add-iframe-element-after-page-has-loaded – newman Nov 27 '14 at 07:04
  • let's say I place 100 of these scripts in the mother.html file - How will I insert the delay between each of these? And secondly, I don't need these to run after the window elements has loaded because this is intended to run in separate path of the mother domain like example-mother.com/mother-maintenance.php – Swayam Nov 27 '14 at 07:08
  • @Swayam make generate by PHP javascript array with urls for iframes. Create in javascript function that will get current element from array, create iframe for this url and increase current number and use setTimeout for call self in period in 10 s. After load page call this function. – newman Nov 27 '14 at 07:17
-1

I think file_get_contents can help you:

<?php
//index.php
set_time_limit(0);

$op_list = array(
    "example.com/operation.php",
    "example123.com/operation.php",
    "example1234.com/operation.php",
);

$opts = array(
    "http" => array(
        "method" => "get",
        "timeout" => 60,
        )
);

$context = stream_context_create($opts);

foreach($op_list as $key => $value)
{
    if($response = file_get_contents($value, null, $context))
    {
        $json_decode = json_decode($response, true);

        echo "{$value}: time_start: {$json_decode['time_start']}, time_end: {$json_decode['time_end']} <br />";
    }
    else
    {
        echo "{$value}: fail <br />";
    }
}

?>

Here is a complete example:

http://try.valinv.com/php/21a6092d20601c77982f7c1ec6b2cc23.html

Flasle
  • 1
  • 3
  • Welcome to Stack Overflow! Whilst this may theoretically answer the question, [it would be preferable](http://meta.stackoverflow.com/q/8259) to include the essential parts of the answer here, and provide the link for reference. – Bowdzone Nov 27 '14 at 09:55