每隔100ms运行一次php脚本(run php script after every 100ms)
是否可以在每100毫秒后运行一个PHP脚本? 此脚本将检查数据库是否有更改,然后更改将反映到其他一些数据库中。 我已经使用触发器做了。 但是我想知道在没有使用Cron和Triggers的情况下是否还有其他方法可以做到这一点。 我将为此目的使用Linux。 谢谢
Is it possible to run a php script after every 100ms ? This script will check a database for changes and then the changes will be reflected into some other database. I am already doing it using Triggers. But I want to know if there is any other way to do it without using Cron and Triggers. I will be using Linux for this purpose. Thanks
原文:https://stackoverflow.com/questions/5762442
更新时间:2020-01-03 21:47
最满意答案
Running something every 100ms almost means that it runs all the time , might as well create a daemon that continuously loops and executes
or use triggers. Essentially on every database change it will copy to another table/db.
2011-04-23
相关问答
问题是您的客户端正在等待您的服务器发送GCM推送通知。 这种行为没有逻辑。 您需要更改服务器端代码以处理API请求,关闭与客户端的连接,然后才发送推送通知。 I've solved my problem thanks to this thread: I'm using Celery to send my notifications through a task queue. I can't believe how simple it is! Thanks anyway :)
你不能。 如果您在每台计算机上使用腻子登录另一台计算机来运行该脚本,该脚本仍将在“另一台”计算机上运行。 您所做的只是使其输出显示在运行腻子的本地计算机上。 这与在服务器上打开多个shell并在每个窗口中运行该脚本完全相同。 如果您希望PHP脚本“本地”运行,那么您需要在将运行该脚本的每台机器上本地安装PHP。 就像我在其他类似问题中所说的那样,有一些PHP编译器可以生成一个可以轻松移植的.exe文件,但不能保证能正常工作。 PHP可以被编译,但并不是所有的脚本都是可编译的。 You can't.
...
您正在从多个线程调用Twisted API。 这是不允许的。 您只能从反应器线程调用Twisted API - 除了几个特定的线程安全API之外。 主要是reactor.callFromThread ,它调度一个函数在反应器线程中运行。 考虑用基于twisted.internet.task.LoopingCall的构造替换SummingThread 。 例如: from twisted.internet.task import LoopingCall
def game_tick(factory,
...
您使用Stopwatch技术是防止代码更频繁执行的最佳解决方案。 正如其他人所说,如果你想确保方法按计划执行,使用Timer是一个更好的解决方案。 基于DateTime任何方法都从根本上被打破,因为它会在日期更改时失败。 在夏令时开关期间尤其明显。 当我们“向前迈进”时,更新可能会快速连续运行两次,因为代码认为自上次更新以来已经过了一个小时。 那不算太糟糕。 但是当我们“退回”时,更新将暂停一整小时,因为最后一次更新时间是提前一小时设置的。 如果您的计算机设置为定期从NTP服务器更新其时间,则可能
...
每100ms运行一次几乎意味着它一直运行,也可以创建一个持续循环和执行的守护进程 或使用触发器。 基本上在每次数据库更改时,它都会复制到另一个表/ db。 http://codespatter.com/2008/05/06/how-to-use-triggers-to-track-changes-in-mysql/ Running something every 100ms almost means that it runs all the time , might as well create
...
实际上, 如果作为事件源的observable调用了OnCompleted() ,它实际上比你想象的更简单。 这将自己做的伎俩: observable.Sample(TimeSpan.FromMilliseconds(100)).Subscribe(log);
这是因为Sample会在其事件源完成时最后一次触发。 这是一个完整的测试: var sub = new Subject();
var gen = Observable.Interval(TimeSpan.FromMilli
...
当您访问您的硬盘时,它可能需要很长时间。 尝试以下方法之一: PRAGMA journal_mode = memory; PRAGMA synchronous = off; 所以它不会立即触摸磁盘。 如果使用得好,SQLite可以非常快。 您可以从缓存中回答小型数据库的select语句。 还有其他方法可以调整您的数据库。 看到这样的其他问题: 提高SQLite的每秒INSERT性能? When you access your hard disk it can take long. Try one
...
$cmd = "php myscript.php $params > /dev/null 2>/dev/null &";
# when we call this particular command, the rest of the script
# will keep executing, not waiting for a response
shell_exec($cmd);
这样做是将所有STDOUT和STDERR发送到/ dev / null,并且您的脚本继续
...
建议/步骤/错误: 创建一个单独的函数来执行ajax请求 在页面加载时调用此函数以在加载页面时运行它 使用setInterval()每n秒调用一次该函数 id应该始终是唯一的。 您现在正在使用verification ,就像