Answer the question
In order to leave comments, you need to log in
How to fork in PHP?
Good day to all.
The following problem arose: It is
necessary to implement the ability to run third-party programs through PHP. These programs are quite resource-intensive, therefore, they must be run in the background.
pcntl is not suitable as PHP should not be run via CGI.
The following idea came to mind: write a C program that takes as a parameter the path to the program to be executed, forks and runs it.
From PHP, this program is called by the exec function:
$cmd = "sudo -u aleksey run_script ".$a['path'];
exec($cmd);
#include <unistd.h>
int main(int argc, char *argv[])
{
pid_t pid;
pid = fork();
if (pid == 0) {
execl(argv[1], NULL);
}
else
return 0;
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question