可以将PHP脚本被安排在特定的时间或特定时间到期后跑

可以将PHP脚本被安排在特定的时间或特定时间到期后跑

本文介绍了可以将PHP脚本被安排在特定的时间或特定时间到期后跑?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写为Android社交游戏云和在服务器上使用PHP。几乎所有的游戏方面将是用户或用户装置驱动,所以大部分的时间,设备将发送到服务器和服务器的请求将反过来,发送到设备的响应。有时,服务器也将发送推送消息的装置,但一般在响应于一个用户的设备的服务器联系

I am writing a social cloud game for Android and using PHP on the server. Almost all aspects of the game will be user or user-device driven, so most of the time the device will send a request to the server and the server will, in turn, send a response to the device. Sometimes the server will also send out push messages to the devices, but generally in response to one user's device contacting the server.

有一个特殊的情况,然而,用户可以在其中设置一计时器和,在给定时间已经过去之后,服务器需要向推送消息发送给所有的设备。这样做的一种方法是将保持定时器本地用户的设备,并且一旦它熄灭,发送信号给服务器发送推送消息。但是,有几个原因,我不想做这种方式。举例来说,如果用户决定不玩了或输了比赛,计时器应该在技术上继续发挥作用。

There is one special case, however, where a user can set a "timer" and, after the given time has elapsed, the server needs to send the push messages to all of the devices. One way to do this would be to keep the timer local to the user's device and, once it goes off, send the signal to the server to send the push messages. However, there were several reasons why I did not want to do it this way. For instance, if the user decides not to play anymore or loses the game, the timer should technically remain in play.

我环顾四周,在PHP中的方法,让我做这样的事情,但我想出了是报警,这是的的我需要什么。我也想过cron作业的,而事实上,他们已经建议就这个问题和其他论坛类似的情况,但由于这是不是一个经常性的事件,而是一个时间事件发生在任意时间点,我不知道一个cron作业是什么,我想无论是。

I looked around for a method in PHP that would allow me to do something like this, but all I came up with were alarms, which are not what I need. I also thought of cron jobs and, indeed, they have been recommended for similar situations on this and other forums, but since this is not a recurring event but, rather, a one time event to take place at an arbitrary point in time, I did not know that a cron job is what I want either.

我目前最好的解决方案包括运行一次,第二次和检查,看看是否这些事件之一是发生在下一秒,如果是这样,发出推送消息cron作业。这是处理这种情况的正确方法,或者有更好的工具,在那里,我只是还没有找到没有?

My current best solution involves a cron job that runs once a second and checks to see if one of these events is to occur in the next second and, if so, sends out the push messages. Is this the proper way to handle this situation, or is there a better tool out there that I just haven't found yet?

推荐答案

soloution 1:
你的PHP文件可以包含一个最终的循环

soloution 1 :your php file can include a ultimate loop

$con = true;
 while($con)
   {
   //do sample operation
   if($end)
      $con = false;
   else
   sleep(5); // 5 seconds for example
   }

soloution 2:
使用cron作业 - 依靠YOUT CP可以按照指令,并在特定时间结果打电话给你的php程序
限制:在cron作业两张电话之间的最短时间为1分钟
结果
soloution 3:
使用一个shell脚本,并调用当过你想你的PHP程序

soloution 2 :use cron jobs -- Depend on yout CP you can follow the instruction and call your php program at the specific times
limit : in cron job the minimum time between two calling is 1 minute
soloution 3 :use a shell script and call your php program when ever you want

这篇关于可以将PHP脚本被安排在特定的时间或特定时间到期后跑?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-03 23:54