Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

popen and poclose under zend-server

I've stumbled upon a phenomenon that I can't explain myself.

I'm using popen to execute php and then execute a php script that way, and pclose to close that. So far so fine. I ran into quite some severe troubles as the script where I used this didn't execute and instead after trying it 3 times in a row I crashed the zend-server (no page would open any more). I found out that the reason to this was that I used a wrong directory for the php.exe. Example:

if (pclose(popen("C:\wrongDir\php\php.exe C:\Zend\Apache2\htdocs\myApp\public\mytest.php 57 > C:\Logs\1\0\jobOut.log 2> C:\Logs\1\0\jobErr.log"))>-1)
{
.....
}

Aside from the "wrongDir" all other dirs were correct....the popen even created the jobOut and jobErr files (which were empty). (remark: PHP is not in a searchpath that is why it wasn't found without the correct path)

Even though I now solved the problem....I have the question if this is a normal behaviour there, or if I have done something wrong (maybe even server settings). As from what I read in the manual about both commands it sounded to me that in the my case I should have had a return value of either -1 or 0 and not the problem I ran into with the process and then the server hanging).

Thanks.

like image 826
Thomas Avatar asked Nov 12 '22 16:11

Thomas


1 Answers

It appears that pclose() doesn't return the exit status of the process but rather of it's ability to close the process.

To get the process termination 'code' use pcntl_wifexited() and pcntl_wexitstatus()

http://php.net/manual/en/function.pclose.php
http://php.net/manual/en/function.pcntl-wexitstatus.php

like image 60
ethrbunny Avatar answered Nov 15 '22 06:11

ethrbunny