每 40 毫秒执行一次 php 脚本? [英] Execute php script every 40 milliseconds?

查看:53
本文介绍了每 40 毫秒执行一次 php 脚本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有什么方法可以每 40 毫秒执行一次 php 脚本吗?不知道cronjob是否正确,因为每秒25次需要大量CPU.

There is some way to execute a php script every 40 milliseconds? I don't know if cronjob is the right way, because 25 times per second require a lot of CPU.

好吧,如果 php 不是正确的语言,我应该使用什么语言?

Well, If php isn't the correct language, what language I should use?

我正在制作一个在线游戏,但我需要一些东西来处理游戏中发生的事情、移动角色、计算弹丸路径等.

I am making a online game, but I need something to process what is happening in the game, to move the characters, to calculate projectiles paths, etc.

推荐答案

如果您尝试每 40 毫秒调用一次 PHP 脚本,将涉及:

If you try to invoke a PHP script every 40 milliseconds, that will involve:

  • 创建流程
  • 加载 PHP
  • 加载并编译脚本
  • 运行编译好的脚本
  • 删除进程和所有内存

你最好把你的工作放到循环体中,然后使用 time_sleep_until 在循环结束时完成剩余的 40 毫秒.然后运行一次 PHP 程序.

You're much better off putting your work into the body of a loop, and then using time_sleep_until at the end of the loop to finish out the rest of your 40 milliseconds. Then your run your PHP program once.

请记住,这需要是一个独立的 PHP 程序;在网页外运行它会导致 Web 服务器在该网页上超时,然后过早结束您的脚本.

Keep in mind, this needs to be a standalone PHP program; running it out of a web page will cause the web server to timeout on that page, and then end your script prematurely.

这篇关于每 40 毫秒执行一次 php 脚本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆