3

I am using a script to open (proc_open) from 5 to 50 processes one after another. Each of them does cURL and posts results to DB. I do not want to wait for their execution results, I just want them to run when the main script is axecuting and after it. I use set_time_limit(10); in each proccess file. proc_close waits for the process to terminate, and returns its exit code. On the web I found that php automatically closes all pipes and each proccess once the main file is completely executed without calling proc_close and fclose but did not find any documented prove.

So the question is: Is it necessary to fclose pipes and proc_close processes? And can it be a problem if 100-200 users run this script at the same time and it opens from 5 to 50 processes for each user and proc_close and fclose are not called. If you have a more elegant way of doing this task please tell me but first of all I need to get the information regarding my current approach. Thanks a lot. The code I use to call each proccess is (part of a function):

        $params = addcslashes(serialize($params), '"');
        $command = $this->phpPath.' -q '.$filename.' --params "'.$params.'"';
        ++$this->lastId;

        $this->handles[$this->lastId] = proc_open($command, $this->descriptorSpec, $pipes);
        $this->streams[$this->lastId] = $pipes[1];
        $this->pipes[$this->lastId] = $pipes;
Nikolay Antonov
  • 170
  • 1
  • 9

0 Answers0