Execute a PHP script from another PHP script

后端 未结 11 1663
伪装坚强ぢ
伪装坚强ぢ 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:37

    you can use the backtick notation:

    `php file.php`;
    

    You can also put this at the top of the php file to indicate the interpreter:

    #!/usr/bin/php
    

    Change it to where you put php. Then give execute permission on the file and you can call the file without specifying php:

    `./file.php`
    

    If you want to capture the output of the script:

    $output = `./file.php`;
    echo $output;
    

提交回复
热议问题