PHP GoDaddy maximum execution time not working

2019-04-09 21:11发布

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.

5条回答
来,给爷笑一个
2楼-- · 2019-04-09 21:24

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=?

查看更多
Emotional °昔
3楼-- · 2019-04-09 21:24

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 enter image description here

查看更多
倾城 Initia
4楼-- · 2019-04-09 21:33

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.

查看更多
Ridiculous、
5楼-- · 2019-04-09 21:35

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);
查看更多
贪生不怕死
6楼-- · 2019-04-09 21:38

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.

查看更多
登录 后发表回答