PHP 守护进程向 Facebook、Twitter 等提交过时状态更新
我正在构建一个应用程序,允许用户将他们的 facebook、twitter、linkedin 帐户链接到我的应用程序,然后通过我的应用程序向所有这些网站发布更新。此外,用户还可以“发布”状态更新。他们可以设置更新的日期和时间,这将导致更新仅在指定日期而不是立即发布到请求的站点。
我已经通过 cron 作业正常工作,该作业提取尚未发布的所有更新(有一个标志指示数据库中是否已发布更新),然后发布它。我使用 cron 每分钟运行这个过程。 现在我的问题是,如果同时设置足够的更新,我将遇到 PHP 最大化执行时间的问题。我立即解决的问题是获取所有具有 post_timestamp
post_timestamp
的更新。 current_timestamp
并尝试发布它们;这样,如果在特定的一分钟内,某些更新尚未发送,则下一次 cron 运行将尝试发送它(如果它仍在最大执行时间限制内)。
我知道这是实现我想要的目标的一种非常蹩脚的方式。因此,我计划有某种守护进程,它继续运行并发布所有过时的更新。 实现这一目标的最佳方法是什么?我正在从事的另一个项目也需要这种守护进程方法。在这方面的任何帮助将不胜感激...:P
提前致谢。
I am building an app that lets users link their facebook, twitter, linkedin accounts to my app and than post updates to all these sites through my app. Additionally user can 'post-date' status updates. They can set a date and time to their update, and which will cause the update to be posted to the requested sites only at the specified date and not immediately.
I have got this working fine with a cron job that pulls out all updates that have not been posted yet (there's a flag indicating whether an update has been posted or not in the DB) and then posting it. I run this process every minute using cron.
Now my issue is that, with enough updates set to the same time, I'll have problems with PHP maxing out the execution time. My immediate work around has been to get all updates which have a post_timestamp < current_timestamp
and try to post them; so that if for a particular minute, some updates have not been sent, the next cron run will try to send it if it is still inside the max execution time limit.
I know this is a very lame ass way of achieving what I want. Hence I plan to have some kind of a daemon process which keeps on running and posts all post-dated updates.
What's the best way of achieving this? I also need this daemon approach for another project I am working on. any help in this regard would be greatly appreciated... :P
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Gearman 可能就是您正在寻找的:http://gearman.org/
Gearman is probably what you are looking for: http://gearman.org/
我编写了许多基于 PHP 的系统,它们执行类似的操作 - 长时间运行的进程无法从频繁的 Cron 作业中运行,因为它不能同时运行。
这是一个三个阶段的过程。
第二部分非常简单。
正确运行上述内容的第一部分甚至更简单。
从字面上看,杀死 runSocialSend.sh 脚本的任何其他实例,然后重新启动它,断开与“控制台”的连接,在后台运行它。
I've written a number of PHP-based systems that do similar things - long running processes that can't be run from a frequent Cron-job as it cannot be allowed to run concurrently.
It's a three-stage process.
The 2nd part of that is quite easy.
The first part to run the above properly is even simpler.
Literally, kill any other instances of the runSocialSend.sh script, and then restart it, disconnecting from the 'console', running it in the background.