dp411805872 2012-12-06 07:57
浏览 84
已采纳

PHP中的多线程使用Javascript ajax,可能吗?

I'm developing a game based on Html5, JavaScript (jQuery) and ajax with the use of PHP as Server Side. Now what is in the game is, there is a different types of jobs that you can assign to you players as per Job time duration. Suppose I have assign one jobJOB1 to one playerPLAYER1 with the duration of 10 minutes and other job JOB2 to other player PLAYER2 with the duration of 30 minuted. Means,

PLAYER1 = JOB1(10MINS)
PLAYER2 = JOB2(30MINS)

Now I want to create multithreading in PHP to handle this two jobs parallel and get the request to client side after every minute complete of that job.

I know that there are various ways to create multithreading in PHP and I can send the request to PHP server to create the thread when job is started with the use of ajax, but how can I get the data back to the client side and display the data after every minute?

It is possible or not? What are other options to do the same thing?

  • 写回答

2条回答 默认 最新

  • duanfan8699 2012-12-06 08:43
    关注

    I think this is more of a task for multiprocessing rather than multithreading.

    To create another PHP thread you would use something like pcntl_fork:

    http://php.net/manual/en/function.pcntl-fork.php

    But in a request/response type situation, such as HTTP, you would more likely start a seperate process and then poll it from the client.

    To do such a thing with PHP you would create another process on the CLI using the & operator (linux only, if you need windows let me know and Ill update the answer), and he poll it using either:

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

报告相同问题?

悬赏问题

  • ¥20 sub地址DHCP问题
  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突
  • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大