Execute a PHP script from another PHP script

后端 未结 11 1604
伪装坚强ぢ
伪装坚强ぢ 2020-12-02 14:04

How would I make my server run a php script by triggering it manually using php? Basically I have a pretty big cronjob file that is ran every 2 hours, but I want to be able

相关标签:
11条回答
  • 2020-12-02 14:54

    I think this is what you are looking for

    <?php include ('Scripts/Php/connection.php');
    //The connection.php script is executed inside the current file ?>
    

    The script file can also be in a .txt format, it should still work, it does for me

    e.g.

    <?php include ('Scripts/Php/connection.txt');
    //The connection.txt script is executed inside the current file ?>
    
    0 讨论(0)
  • 2020-12-02 14:55

    The OP refined his question to how a php script is called from a script. The php statement 'require' is good for dependancy as the script will stop if required script is not found.

    #!/usr/bin/php
    <?
    require '/relative/path/to/someotherscript.php';
    
    /* The above script runs as though executed from within this one. */
    
    printf ("Hello world!\n");
    
    ?>
    
    0 讨论(0)
  • 2020-12-02 14:57
    <?php
    $output = file_get_contents('http://host/path/another.php?param=value ');
    echo $output;
    ?>
    
    0 讨论(0)
  • 2020-12-02 14:57

    Possible and easiest one-line solution is to use:

    file_get_contents("YOUR_REQUESTED_FILE");
    

    Or equivavelt for example CURL.

    0 讨论(0)
  • 2020-12-02 14:58

    I prefer to use

    require_once('phpfile.php');
    

    lots of options out there for you. and a good way to keep things clean.

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