PHP /暂停/连接到服务器复位?

PHP /暂停/连接到服务器复位?

问题描述:

我有一个PHP脚本,需要很长一段时间运行。

I have a php script that needs to run for quite some time.

什么是脚本的:


  • 连接到MySQL

  • 的任何地方发起从100到100,000卷曲请求

  • 每个卷曲请求返回的1至2000年房地产上市紧凑德codeD数据 - 我使用preG-全匹配来获取所有数据,并做每个商家信息存在一个MySQL的插入。每个查询不会超过超过1MB的数据更多。

所以有很多循环,MySQL的插入和卷曲的请求回事。 PHP安全模式是关闭的,我能够成功的ini_set最大,执行时间,以荒谬的东西,让我的剧本跑,一路过关斩将。

So there are a lot of loops, mysql inserts, and curl requests going on. php safe mode is off and I am able to successfully ini_set the max-execution-time to something ridiculous to allow my script to run all the way through.

好吧,我的问题是脚本或Apache或东西是具有在脚本中间的行程和屏幕变成了连接服务器已经重启屏幕。

Well, my problem is the script or apache or something is having a stroke in the middle of the script and the screen goes to the "connection to the server has been reset" screen.

任何想法?

好了,不顾事实,试图100000卷曲的要求绝对是疯了,你可能会碰到内存限制。

Well, disregarding the fact that attempting 100,000 cURL requests is absolutely insane, you're probably hitting the memory limit.

尝试将内存限制设置为更合理的:

Try setting the memory limit to something more reasonable:

ini_set('memory_limit', '256M');

而作为一个侧面小费,不设置执行时间,以什么可笑的,机会是你最终会找到一个方法来打的像这样的脚本。 ]

And as a side tip, don't set the execution time to something ludicrous, chances are you'll eventually find a way to hit that with a script like this. ;]

相反,只需将其设置为 0 ,其功能等同于打开执行限制完全关闭:

Instead, just set it to 0, it functionally equivalent to turning the execution limit off completely:

ini_set('max_execution_time', 0);