php - make Proc_Open work synchronously -
I have PHP scripts that rely on shell_exec () and (consequently) 99% of the time worked. The script executed a PhantomGs script that produced an image file. Then using more PHP, that image file was processed in a certain way. The problem was that the shell_exec () on the occasion would cause hanging and usability issues. Reading this I found out that shell_exec () is the problem and hanging on proc_open will solve hanging.
The problem is that while shell_exec () proc_open is waiting for the execution command to finish, and so follow the PHP commands and fails to work on the generated image because the image is still Being prepared I'm working on Windows so pcntl_waitpid is not an option.
My initial approach was to get some output for proc_open for continuous reading of the PhantmJs. You can see what I tried to do in this thread:
I could not get it to work and it seems that someone else has a solution for me So what I'm asking now is, how can i proc_open synchronously work like synchronously shell_exec? I need the remaining PHP commands in my script, until the proc_open command expires.
Adding your code as per the first comment request:
ob_implicit_flush (true); $ Descriptorspec = Array (0 = & gt; array ("pipe", "r"), // stdin 1 => array ("pipe", "wa"), // stdout 2 = & gt; array "Pipe", "w") // stderr); $ Process = proc_open ("c: \ phantomjs \ phantomjs.exe /test.js", $ descriptors, $ pipe); If (is_resource ($ process)) {while (FIF ($ pipe [1])) {$ return_message = fgets ($ pipe [1], 1024); Break if strlen ($ return_message) == 0; Echo $ refund_message '& Lt; Br / & gt; '; Ob_flush (); Flush (); }}
Here is the PhantomJS script:
interval = setInterval (function () {console.log ("x");}, 250); Var page = requirement ('webpage'). Create (); Var args = requires ('system'). Args; Page.open ('http://www.cnn.com', function () {page.render ('test.png'); phantom.exit ();}); Instead of "C: \ phantomjs \ phantomjs.exe /test.js" I use a cmd.exe ping form exmaple, I get line after the $ return_message print line, so I know Proc_open receives a stream I'm trying to do this with the phantom script.
Comments
Post a Comment