dta43039 2012-07-23 19:31
浏览 65
已采纳

PHP调用shell脚本来处理多个用户

I have a C simulation for which I'm creating a graphical web interface. I used HTML with ajax to call PHP, which in turn calls the shell to run the simulation. The output is then passed back to the webpage.

The script generates an output file (with a link outputted to the webpage) as well as a graph (using a call to gnu plot and referencing the output file). The webpage also allows the user to upload an input file which is used in the C simulation. All of these files are user specific.

If there is only one user on the webpage at a time, there isn't any problem. However, if 5 people want to run the simulation at the same time, the user-specific files (output, graph, input) would all be getting overwritten and messed up.

I don't have any MySQL experience, and I also don't plan on saving the outputs or inputs for a given user (user can download them if he/she wishes), so I was hoping there might be a rather simple solution like, for example, generating a temporary directory on the server with some sort of identifying tag in the name based on the user's IP address or something. This folder could then be removed some number of minutes after the simulation runs. Anyone have any ideas about something like that?

Or will I have to resort to MySQL?

Edit: It would also be okay to have something like allowing a maximum of 5 users running at the same time and then create a queue for additional users, but that might be even more difficult.

Thanks, Josh

  • 写回答

3条回答 默认 最新

  • dongshuo1856 2012-07-23 19:43
    关注

    You can't do it without saving the output somewhere, so your temp dir plan is fine.

    • Assign each new user a unique id, via md5() or sha1() or whatever.
    • Pass the id to the simulator and have it create its output files in a subdirectory named by that id.
    • Render the links and image HREFs according to that id..
    • Write a cron to periodically purge the stale subdirs.

    Each person will get their own output set, on an unguessable URL.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 2024-五一综合模拟赛
  • ¥15 如何将下列的“无限压缩存储器”设计出来
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口