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:
https://i.sstatic.net/JsxXC.jpg
https://i.sstatic.net/jiZJI.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.
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.