PHP exec() return value for background process (linux)

前端 未结 3 1077
南方客
南方客 2020-12-22 04:02

Using PHP on Linux, I\'d like to determine whether a shell command run using exec() was successfully executed. I\'m using the return_var parameter to check for a successful

3条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-22 05:09

    Not using the exec() method. When you send a process to the background, it will return 0 to the exec call and php will continue execution, there's no way to retrieve the final result.

    pcntl_fork() however will fork your application, so you can run exec() in the child process and leave it waiting until it finishes. Then exit() with the status the exec call returned. In the parent process you can access that return code with pcntl_waitpid()

提交回复
热议问题