4

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.

4
  • godaddy uses a shared php.ini for all hosts, so make sure you've put it in the absolute root of your hosting directory. Commented May 4, 2015 at 3:26
  • if you use godaddy for hosting, your going to have a bad time Commented May 4, 2015 at 3:35
  • I spent whole day but did not find any solution. I could not understand why it doesn't working. If I put php.ini in wrong directory, phpinfo() should remain the default value (max_execution_time=120), isn't it? This is very weird, phpinfo() get updated but the server doesn't. Commented May 4, 2015 at 9:17
  • for (;;) will execute that for loop as quickly as possible forever. This means it'll use 100% CPU to run that loop. Try for (;;) { sleep(100); } or better yet just sleep(601) Commented Jun 19, 2015 at 18:51

5 Answers 5

2

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.

Sign up to request clarification or add additional context in comments.

1 Comment

You are right. Finally they told me GoDaddy doesn't allow long execution unless I use VPS or dedicated server.
1

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.

Comments

0

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

2 Comments

I have tried set_time_limit(600) and set_time_limit(0) but still not working.
I can only conclude that godaddy doesnt allow you to change it. Open a support ticket and ask them.
0

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

4 Comments

php located at usr/bin/ folder, max_execute_time=120, max_input_time=60.
Are you using cpanle in GoDaddy server . find the correct loaded php.ini file 1.from phpinfo page and 2 .php -i | grep php.ini open both file and change max_execution_time = 300 not 120
Yes I am using GoDaddy Linux cPanel shared-hosting. phpinfo() show me my loaded configuration file is my custom php.ini (/home/myaccount/public_html/php.ini) but "php -i | grep php.ini" show me the loaded configuration file is GoDaddy default php.ini (usr/local/lib/php.ini) I have no authority to modify GoDaddy default php.ini file. Is this the reason caused my custom php.ini not take effect?
Then no way to enable it , In Shared hosting everything depends on Policy . what policy go daddy used . php execution is one kind of thread so its normally not allowed at server .
0

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.