PHP GoDaddy maximum execution time not working

青春壹個敷衍的年華 提交于 2019-12-06 06:43:53

问题


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.

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 file:

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

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>

Screen shots:

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

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

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

Latest updates

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.

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";  
?>

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

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";

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 (;;) ;

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

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.


回答1:


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 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.




回答2:


This post enabled me to increase my PHP limit.

Key information:

  1. Open an SFTP connection to your GoDaddy hosting account

  2. In the same directory as wp-config.php, create a .user.ini file.

Note the leading .

  1. In this .user.ini file add max_execution_time = 180

This will increase the GoDaddy max_execution_time to 3 minutes.




回答3:


Add this to at the top of your php script:

set_time_limit(600);
//or set_time_limit(0); unlimited time
ignore_user_abort(1);



回答4:


Place this at the top of your PHP script

ini_set('max_execution_time', 300); //300 seconds = 5 minutes

if it works then then run

whereis php

Check the output folder location and go this location php.ini file . check max_input_time=?




回答5:


Godaddy do not allow to update server configuration by default. Even though you find path og php.ini you will not have access to edit via SSH/FTP client as per their policy.

Solution : The only solution which I found was Call to Godaddy support. Once they allow permission you will be able to find editable field in following path for PHP variables.

Path : Home > Software > PHP Version > Switch to PHP Options



来源:https://stackoverflow.com/questions/30022099/php-godaddy-maximum-execution-time-not-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!