简体   繁体   English

Rackspace,负载平衡,flush()和cURL

[英]Rackspace, load balancing, flush(), and cURL

First off, I apologize if this question is vague or confusing. 首先,如果这个问题含糊不清或令人困惑,我道歉。 The truth is, I'm pretty confused about what's going on, and I'm even more confused about how to remedy it. 事实是,我对正在发生的事情感到很困惑,而且我对如何纠正它更加困惑。

I am working on a Rackspace cloud server. 我正在使用Rackspace云服务器。 As you hopefully know (if you are reading this question) Rackspace employs a load balancer which tends to kill scripts that last over 30 seconds. 正如您所希望的那样(如果您正在阅读此问题),Rackspace会使用负载均衡器,这种负载均衡器可以杀死持续超过30秒的脚本。 Unfortunately, I am working on a huge processing script that involves the transfer of many large files. 不幸的是,我正在处理一个涉及许多大文件传输的巨大处理脚本。 Needless to say, the script can take as much as an hour to run sometimes. 不用说,脚本有时可能需要一个小时才能运行。 Fortunately, this script doesn't need to be run too often. 幸运的是,这个脚本不需要经常运行。 Unfortunately, I am stuck with the Rackspace cloud—for my boss, upgrading is simply not an option. 不幸的是,我坚持使用Rackspace云 - 对于我的老板来说,升级根本不是一个选择。

By using PHP's flush() function, coupled with some menial whitespace, I am able to avoid this timeout issue nearly always. 通过使用PHP的flush()函数,加上一些琐碎的空白,我几乎总能避免这个超时问题。 It's not a great solution, but given my limitations and the use of my transfer script, it works pretty well. 这不是一个很好的解决方案,但考虑到我的限制并使用我的传输脚本,它的效果非常好。

...when I load the script in my browser. ...当我在浏览器中加载脚本时。

When I try to call the script with a cron job, the script just times out. 当我尝试使用cron作业调用脚本时,脚本会超时。 It times out when I try to call it from Hurl.it as well. 当我尝试从Hurl.it调用它时,它会超时 However, when I load it in the browser, everything seems to work again. 但是,当我在浏览器中加载它时,一切似乎再次起作用。

How can I remedy this issue? 我该如何解决这个问题? I need to call this script using a cron job, but no matter what I do, it seems to always fail. 我需要使用cron作业调用此脚本,但无论我做什么,它似乎总是失败。

Thanks for the help! 谢谢您的帮助!

Depends on what is timing out the script. 取决于脚本的超时时间。

If it's the racksace load balancer timing out, you are able to adjust the load balancer timeout through the API up to 120 seconds. 如果它是racksace负载平衡器超时,您可以通过API调整负载平衡器超时最多120秒。 If you need the script to run longer than that, you will probably need to split up the work into several smaller sections. 如果您需要脚本运行的时间超过此时间,则可能需要将工作拆分为几个较小的部分。 This is a good idea anyway because a long execution time invites problems of network dropouts where several smaller scripts can be run and each validated more easily. 无论如何,这是一个好主意,因为较长的执行时间会引发网络丢失问题,其中可以运行几个较小的脚本,并且每个脚本都更容易验证。

Ref: 参考:

=== If you're hitting the php.ini max_execution_time, then calling set_time_limit(20) each iteration through a loop (I don't know anything about your code) or similar, will continually reset the timer. ===如果你正在点击php.ini max_execution_time,那么每次迭代循环调用set_time_limit(20) (我对你的代码一无所知)或类似情况,都会不断重置计时器。

From php.net: 来自php.net:

When called, set_time_limit() restarts the timeout counter from zero. 调用时,set_time_limit()从零重新启动超时计数器。 In other words, if the timeout is the default 30 seconds, and 25 seconds into script execution a call such as set_time_limit(20) is made, the script will run for a total of 45 seconds before timing out. 换句话说,如果超时是默认的30秒,并且脚本执行25秒,则进行诸如set_time_limit(20)之类的调用,脚本将在超时之前运行总共45秒。

Ref: 参考:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM