stinseid stinseid - 1 year ago 76
PHP Question

How to perform PHP shell_exec a java class in parallel?

I am executing java classes from php.

For testing purposes, I have a php page. When I navigate to that page, it executes a java program that waits 5 seconds and outputs something.

It appears that when i navigate to the page at the same time from different browser windows, the first window takes 5 seconds to output the message, the second one takes 10 seconds, the thrid one 15 seconds and so on.

What I want is for the java processes to run in parallel, so that all windows output the result roughly at the same time, but I have no idea how to do this. I feel like there is an easy solution, but I just cannot find it anywhere on the internet.

I have also tried to use executing it with

to run in the background, but the same thing happens.

Answer Source

It seems you have some locking problem in place that prevents the parallel execution. Are you using the PHP session module? The default session storage module stores the session data in a file that is locked during the execution of a page. If you load the page twice in the same browser, the second request is blocked by the session module until the first request finishes.

Perform the second request in another browser to check if that is your problem. If so, you can call session_write_close() to release the lock if you don't require to store any more data in the session.