PHP GoDaddy的最大执行时间不起作用 [英] PHP GoDaddy maximum execution time not working

查看:84
本文介绍了PHP GoDaddy的最大执行时间不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

默认的maximun_execution_time为120秒。我已按照所有说明创建php.ini文件,并将其放置在正确的位置public_html中。我运行phpinfo()并发现maximun_execution_time已成功调整为600秒。

The default maximun_execution_time is 120 seconds. I have followed all instructions to create php.ini file and placed in correct location public_html. I ran phpinfo() and found that the maximun_execution_time has successfully adjusted to 600 seconds.

但是问题在于它仍然无法执行超过120秒的脚本。在执行2分钟后,它将返回错误代码500 Internal server error。

But the problem is it still not able to execute the script which more than 120 seconds. It will return error code 500 Internal server error after 2 minutes of execution time.

sleep.php文件:

sleep.php file:

<?php
    $sleepTime = isset($_POST['sleepTime'])? intval($_POST['sleepTime']): 0;
    sleep($sleepTime);
    echo " woke up";    
?>

sleep.html文件:

sleep.html file:

<script>
    var beginSleep=function() {
        var timeNow = new Date();
        $('input[type=button]').attr("disabled", true);
        $('#msg').html(timeNow.getHours()+":"+timeNow.getMinutes()+":"+timeNow.getSeconds()+" Sleeping...<br>");
        $.ajax({
            url: "sleep.php",
            data: $('#formSleep').serialize(),
            type:"POST",
            dataType:'text',
            success: function(msg) {
                timeNow = new Date();
                $('#msg').append(timeNow.getHours()+":"+timeNow.getMinutes()+":"+timeNow.getSeconds()+msg);
                $('input[type=button]').removeAttr("disabled");
            },
            error:function(xhr, ajaxOptions, thrownError) {
                alert(xhr.status);
                alert(thrownError);
            }
        });
    };
</script>

<form id="formSleep" method="post" action="sleep.php">
    <p>Sleep time(seconds):</p><input type="text" name="sleepTime" value="5" />
    <input type="button" value="submit" onclick="beginSleep()" />
</form>
<p id="msg"></p>

屏幕截图:

http://i.imgur.com/IAiSpPS.jpg

http://i.imgur.com/w7A1nKA.jpg

如果将睡眠时间设置为121秒并提交,它将不会返回唤醒消息,但会提示错误代码500。

If I set sleep Time to 121 second and submit, it won't return the "woke up" message but prompt the error code 500.

最新更新

我已经与GoDaddy支持人员交谈,他们说我的php.ini可以正常工作,因为他们可以看到max_execution_time值已更改为600秒。但是他们无法回答我为什么发生超时问题。他们坚持认为这是我的脚本问题,并说我的测试脚本对于测试执行时间无效。

I have talk to GoDaddy supports, they said my php.ini working correctly because they can see the max_execution_time value has changed to 600 seconds. But they couldn't answer me why the timeout problem happen. They insisted this is my scripting problem and saying my test script is not valid for testing execution time.

我向他们展示了另一个我认为是最简单的测试脚本。该消息将永远不会显示,因为它超过了120秒,它将返回错误代码500内部服务器错误。

I showed them another test script which I believe is the most simple one. The message will never show because it exceed 120 seconds and it will return error code 500 internal server error.

<?php
    sleep(121); echo "sleep(121) completed";  
?>

他们向我展示了他们的测试脚本,并声称max_execution_time设置可以正常工作。

They showed me their test scripts and claimed that the max_execution_time setting is working fine.

test.php:test.php将在30秒后重定向到我的主页。

test.php: The test.php will redirect to my homepage after 30 seconds.

header( "refresh:30; url=http://my-site.net" );
echo "please wait 30 seconds";

他们展示给我的另一个测试脚本是一个无限循环 for(;;);。该测试脚本超过120秒时也会自动超时。除此之外,无限循环消耗了我80%的CPU资源。

Another test script they showed me is an infinity loop "for(;;) ;". This test script also timeout automatically when it exceed 120 seconds. Beside that the infinity loop consumed 80% of my CPU resources.

register_shutdown_function(function() {
    echo "shutdown function called\n";
});

set_time_limit(600); // Set time limit to 1 second (optional)
for (;;) ;

他们得出的结论是,我的max_execution_time无法正常工作是由于我没有足够的CPU资源。

They concluded that my max_execution_time not working correctly is due to I don't have enough CPU resources.

我不相信他们说的话,因为sleep()不会占用太多资源。我尝试并行运行测试脚本,但CPU使用率为0%。除此之外,我认为header( refresh:30,url = ...)函数不能算作长时间运行的脚本。 GoDaddy支持服务不如我预期的那么好。

I don't believe what they said because sleep() doesn't use much resources. I have tried ran the test scripts parallely but the CPU usage was 0%. Beside that, I don't think header( "refresh:30", url=...) function could count as a long running script. GoDaddy support service is not as good as I expected.

推荐答案

000webhost和bluehost和ProISP都存在相同的问题,任何运行PHP的进程无论设置如何,超过120秒将被终止,以防止服务器过载,并且您必须向工程师(实际上知道问题出在哪里)请求您的帐户/脚本来获得此安全功能的豁免(祝您好运) 。只有ProISP实际上为我提供了1个特定php脚本的豁免。-或您可以购买VPS(例如ramnode.com),或使用没有此限制的虚拟主机(如syse.no) ),或使用可能愿意为您提供豁免的
的虚拟主机(例如proisp.no)

Same problem with 000webhost and bluehost and ProISP, any PHP process running for more than 120 seconds will be terminated, regardless of settings, to prevent the server from overloading, and you must ask a engineer (that actually know what the problem is) for your account/script to get an exemption from this security feature (good luck. Only ProISP actually gave me an exemption for this, for 1 specific php script..) - or you could buy a VPS (ex, ramnode.com ) , or use a webhost that doesn't have this limitation (like syse.no ) , or use a webhost that might be willing to give you an exemption (like proisp.no )

GoDaddy的支持人员受到了阻碍。为什么? header( refresh:30; url = http://my-site.net );
这将使您的浏览器重定向,并且与php执行时间无关,并且他们无法找到问题的真正原因,并且真正的问题与您的cpu的使用无关。

GoDaddy support staff are retarded. why? header( "refresh:30; url=http://my-site.net" ); this will make YOUR BROWSER redirect and has nothing to do with php execution time, and they were unable to find the real cause of the problem, and the real problem has nothing to do with your cpu usage.

这篇关于PHP GoDaddy的最大执行时间不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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