drne47241 2015-03-20 20:31
浏览 57

php - 一个jar文件的后台进程,如何在进程完成时异步通知?

Scenario: I have a php vagrant virtualbox server and a runnable jar that takes up to some minutes to run. Ideally, when the user goes to a certain route in my application, the server will start running said jar in the background so the user wont have to wait looking at a blank page, and, when the jar finishes executing, the page will automatically refresh(or the data in it) giving the user information that it got from the output of the jar.

Problem: So far, I managed to run the jar in the background using exec() function. I can even get the process id and check if it is still running or not. The problem i have is how can the php(per say) be notified when the jar stops running without blocking the normal execution? Is there even any way to do this? I've searched everywhere from laravel queues to forking the running process but nothing(as i understood) suits my needs.

EDIT: I think I may have found a solution but i would like to ask the community anyway. Say I use a javascript loop (with setInterval) after the page loads, and ,inside the loop, i make an ajax async request to the server asking if the process has ended, and, if so, bringing back the output of the jar and updating the web page with the new data. This would make for a very "pull" solution instead of the preferable "push" but I don't even know it the push approach is possible.

I'm still learning to code for web app and so this might be a silly question and for that I apologize. Please feel free to put me in the right path if this solution is completely off the rails.

Thanks in advance,

  • 写回答

1条回答 默认 最新

  • doumei2023 2015-03-22 03:46
    关注

    You should take a look at JS librairies already made for such purpose ex: NodeJS.

    It keeps a pipe open between the user and your webserver and you can send a notice from the server to a specific user or a group of user.

    Really love it myself.

    评论

报告相同问题?

悬赏问题

  • ¥15 想问一下树莓派接上显示屏后出现如图所示画面,是什么问题导致的
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号