How to make php script run another php script

前端 未结 9 1339
小蘑菇
小蘑菇 2021-02-07 15:45

I\'m trying to do exactly the same thing as in my previous Python question, but in PHP. See my previous (answered) question

PHP script from previous question does someth

相关标签:
9条回答
  • 2021-02-07 16:17

    You can do it by placing header('Location: second.php'); at the end of first.php and again at the end of second.php to start executing third.php and so on. Even you can create cycles between two scripts, i.e after ending first.php, second.php will be started and after executing second.php again the first.php, again second.php and so on.

    But remember, this is a browser dependent feature and how many script can be executed one after another, totally depends on how many times that browser permits redirection. I found mozilla allows 23 redirections, that means you can executes 23 scripts one after another.

    0 讨论(0)
  • 2021-02-07 16:17

    To run a second script on the same server

    $appUrl = $_SERVER['HTTP_HOST'];
    $path = 'second.php';//your path here
    $appUrl = 'http://'.$appUrl.'/'.$path;
    file_get_contents($appUrl);
    
    0 讨论(0)
  • 2021-02-07 16:22

    To the best of my knowledge, there isn't any way to run a second page (AJAX is the exception). As far as I know, PHP doesn't support multiple threads (please correct me if I'm wrong) and the 'single-thread' nature of the web seems to defeat it anyways.

    I would rather be inclined to look at your specific application and find out why you need to have two separate pages run - and then re-engineer the process so it does not.

    I'd be willing to bet that a re-engineer would end being less of a headache from a development standpoint, as well as a logic and implementation one.

    0 讨论(0)
提交回复
热议问题