Multiple simultaneous calls to exec prevents the program from proceeding

I have a php file that is requested from 3 different browsers simultaneously and repeatedly. This php file starts a process using exec(). Given that the php file is requested several times, exec() also occurs repeatedly.

I got unwanted results after a while so I had to start testing.

This is what it looks like when it goes according to the instructions:

  1. php starts
  2. php calls exec()
  3. exe does its thing and returns
  4. php done

5/5 times it will be as above, but all of a sudden it will be like this instead:

  1. php starts
  2. php calls exec()
  3. exe does its thing and returns
  4. php does not proceed from exec, even though the child process has ended. (step 3)

The interesting thing is that when it gets stuck at exec, it is released when another request to the same script has been completed.

I can not figure out what’s going on here. I really hope someone else has an idea

Have you used the second and third parameters of the exec() function to see if there is any error info being returned and or an error result code? This might tell you more of what is going on. Also is the exec() function returning false in this scenario?

Perhaps something is going on in the external program and it isn’t properly telling PHP that it has ended because it ended abnormally. Could be a simple exception being thrown or maybe some kind of race condition. Let us know if, and what kind of, errors you might be seeing.

Hello Martyr. Hope everything’s allright!

When the script finally continues from exec, exec returns without problem. Both the output and the return-status is as usual, non error.

The exe returns without problem, I know because it writes to a log. Then its parent (the php script) doesn’t continue, it waits. BUT, it later continues as mentioned earlier when another request to the same script has been completed. I dont know if it continues when the other entire script has reached the end or as soon as the exec part of the other script is done. But one of the scenarios happens.

I have a try catch, nothing gets thrown.

The exe files monitor different path’s in windows. When something happens in a directory they return. So when the php-script gets stuck at exec, at the exact time that I make a change/edit in a direcotry that another php-script child process is monitoring then the locked/stucked script finally continues (and it has the program output and everything’s alright)

Anyone? Any thoughts?

What is the real problem you are trying to solve with this code?

A sample script would be helpful to enable users to experiment.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.