Daemonize php file on a remote machine

I am trying to invoke beanstalk workers on remote machines from a management server.

I have a function that takes a host name, SSHes on a private network to a target machine, and then runs commands on that computer.

The command I use to create jobs (when I do this manually at the prompt on the target server):

nohup /path/to/php /path/to/file/worker.php &

The way out of this:

nohup: ignoring input and appending output to `nohup.out'

To return to the invitation, ctrl + c is required

When I do this from a remote machine, a script runs and it shows the output "worker", which sits there and waits for work. I need ctrl + c to return to the tooltip.

When I run this command with php in the browser, it launches the working one, but the browser just freezes after that and eventually hits the nginx timeout. I assume this is because shell_exec (), which I use to run the command, is waiting for an invitation after running this command, but it requires ctrl + c, so it believes that the command has not finished executing.

How can I make him return to the invitation after running this command?

+3
source share
1 answer

You can create dameon in PHP in many ways. There are libraries for this,

The idea is pretty simple.

  • Skip child process and exit parent
  • Close all stdin, stdout, stderr and never output anything.
+1
source

All Articles