PHP的最长执行时间

时间:2012-06-20 16:39:49

标签: php

我正在努力从网站下载图片,并出现错误"Maximum execution time of 30 seconds exceeded"并停止下载图片。我尝试添加以下代码行,我认为可以解决问题:

ini_set('max_execution_time', 0); //zero means forever I think, I also tried 200 or 300 seconds

它没有给我错误但是执行停止了(我的意思是图像停止下载)。

如何让执行时间延长300秒?对此有什么解决方案吗?

提前致谢!

编辑:

function save_image($inPath,$outPath)
    { 
$in=    fopen($inPath, "rb");
$out=   fopen($outPath, "wb");
while ($chunk = fread($in,8192))
{
    fwrite($out, $chunk, 8192);
}
fclose($in);
fclose($out);
    }

方法调用:

foreach($li->find('a[class=thumbnail]') as $img) 
                    {
                        foreach($img->find('img') as $e)
                        {   
                            $image++;           
                           echo "<img src=\"" . $e->src . "\"/>" . "<br>";
                           save_image($e->src, 'thumbs/image'. $image .'.JPG');

                        }

                    }   

这是我正在使用的代码

3 个答案:

答案 0 :(得分:2)

set_time_limit(0);

确保它位于文档的顶部,就在<?php

之后

答案 1 :(得分:2)

或者,您可以更改php.ini文件中的max_execution_time,使其符合您的需要。

答案 2 :(得分:1)

您应该使用set_time_limit(0)php.net)代替。

相关问题