简体   繁体   English

如何并行执行PHP shell_exec Java类?

[英]How to perform PHP shell_exec a java class in parallel?

I am executing java classes from php. 我正在从PHP执行Java类。

For testing purposes, I have a php page. 为了测试,我有一个php页面。 When I navigate to that page, it executes a java program that waits 5 seconds and outputs something. 当我导航到该页面时,它将执行一个等待5秒并输出内容的Java程序。

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. 看来,当我从不同的浏览器窗口同时导航到该页面时,第一个窗口需要5秒钟来输出消息,第二个窗口需要10秒钟,第三个窗口需要15秒钟,依此类推。

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. 我想要的是让Java进程并行运行,以便所有Windows大致同时输出结果,但是我不知道该怎么做。 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 nohup and & to run in the background, but the same thing happens. 我也尝试过使用nohup&在后台运行它,但是发生了同样的事情。

It seems you have some locking problem in place that prevents the parallel execution. 似乎您有一些锁定问题阻止了并行执行。 Are you using the PHP session module? 您正在使用PHP会话模块吗? 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. 如果是这样,如果不需要在会话中存储更多数据,则可以调用session_write_close()释放锁。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM