我怎样才能保持一个Amazon SQS PHP reciever脚本运行下去? [英] How can I keep an Amazon SQS PHP reciever script running forever?

查看:240
本文介绍了我怎样才能保持一个Amazon SQS PHP reciever脚本运行下去?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有previously使用的Gearman以及主管管理工作。

I've previously used Gearman along with supervisor to manage jobs.

在这种情况下,我们使用Amazon SQS我花了一些时间去各地让我的头。

In this case we are using Amazon SQS which I have spent some time trying to get my head around.

我已经建立了我们的主要的Web服务器的独立微型实例作为图像处理服务器使用(纯粹用于测试的那一刻,它也将升级,并成为集群的一部分,在此之前实现去住)

I have set up a separate micro instance from our main webserver to use as an Image processing server (purely for testing at the moment, it will be upgraded and become part of a cluster before this implementation goes live)

在这条微比如我曾经为了进行图像处理安装PHP和ImageMagick的。

On this micro instance I have installed PHP and ImageMagick in order to perform the image processing.

我也写这从Amazon SQS接收消息的工人脚本。

I have also written a worker script which receives the messages from Amazon SQS.

所有作品完美,但我需要这个脚本,才能不断检查邮件运行一遍又一遍。

All works perfectly, however I need this script to run over and over again in order to continuously check for messages.

我不喜欢运行的连续循环,所以开始寻找其他方法收效甚微的想法。

I don't like the thought of running a continuous loop so have started to look at other methods with little success.

所以我的问题是什么是通常被认为是最佳实践的方式来做到这一点?

So my question is what is generally considered the best practice way to do this?

我担心的内存,因为PHP是不是真的为此设计的,因此感觉就像在运行脚本了一会儿,然后停止和重新启动可能是我最好的选择。

I am worried about memory since PHP wasn't really designed for this, therefore it feels like running the script for a while, then stopping and restarting it might be my best bet.

我有使用经验的主管(确保Gearman的工人不停地奔跑),并想知道如果我可以简单地用它来不断地一遍又一遍地执行简单的PHP脚本?

I have experience using supervisor (to ensure that gearman workers kept running) and am wondering if I could simply use that to continuously execute the simple php script over and over?

我的想法如下:

  • 设置了SQS长轮询,以便脚本检查,持续20秒。
  • 使用whil​​e循环用20秒的睡眠,以保持这个脚本运行比如说一个小时的时间
  • 在拥有这一切贯穿主管。当小时就到了,并且循环完成后,允许脚本退出。
  • 在主管应该然后自动重新启动

这听起来可行?有没有更好的办法?什么是通常被认为是最好的做法,用于接收PHP SQS消息?

Does this sound viable? Is there a better way? What is generally considered the best practice for receiving SQS messages in PHP?

在此先感谢

推荐答案

supervisord 你可以设置自动重启来把它一遍又一遍运行命令。请参阅: http://supervisord.org/configuration.html#program-x-section -settings

In supervisord you can set autorestart to true to have it run your command over and over again. See: http://supervisord.org/configuration.html#program-x-section-settings

总体而言,用一个无限while循环是完全正常的,PHP将能正确释放你的对象,并保证内存检查,如果正确写入。它没有泄漏可以运行数年(如果有泄漏,你可能创造了它自己,因此请检阅code)。

Overall, using an endless while loop is perfectly fine, PHP will free your objects correctly and keep memory in check if written correctly. It can run for years without leaks (if there's a leak, you probably created it yourself, so review your code).

<一个href="http://stackoverflow.com/questions/18414209/how-do-i-stop-a-supervisord-process-without-killing-the-program-its-controlling/20299217">How做我停止Supervisord过程中无查杀程序它的控制可能是你的兴趣?;在OP也有类似的设置,具有自动重启,想正常关闭添加到它。

How do I stop a Supervisord process without killing the program it's controlling? might be of interest to you; the OP had a similar setup, with autorestart and wanted to add graceful shutdowns to it.

这篇关于我怎样才能保持一个Amazon SQS PHP reciever脚本运行下去?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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