PHP scripting process

How can I create a process on a PHP page to run a program that will survive the execution of a request?

In other words, I want the page to have a normal lifespan (a few milliseconds), but run a program that continues to run on the server. Thanks

+6
source share
2 answers

Use this code:

<?php exec('nohup /usr/bin/my-command > /dev/null 2>&1 &'); ?> 

This expands the subprocess in the background and writes all the output to /dev/null . Thus, PHP continues to execute the script as if there would be no output that it should wait.

+12
source

I suggest you use CRON if you need to start the process on time.

0
source

Source: https://habr.com/ru/post/906561/


All Articles