php exec() function and different hosts

后端 未结 3 1946
时光说笑
时光说笑 2021-01-21 08:20

I have a script that executes a file in a couple of directories down which looks like this:

exec(\"php-cli $file_path > /dev/null 2>/dev/null &\"); //p         


        
3条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-01-21 09:02

    It depends on how the PHP-CLI binary is compiled. On most systems the executable is named just 'php' and I guess that the hosts that have 'php-cli' have it compiled by hand, while most of the others have it installed via the OS package manager.

    You have two options to work around that and make it "universal":

    1. On each of the servers, add an alias for one of them where needed, or make a symlink to the PHP executable somewhere (e.g. in your home directory).
    2. Prior to executing, check which one of them exists (usually, it should be located in /usr/bin/) and set it to a variable.

提交回复
热议问题