2

I have a PHP script that will be executed by requests from the application admins. It does lots of stuff and takes at least 20 minutes(depending on the database size)

the Apache TimeOut directive is set to 300(5 minutes) which closes the connection and returns 500 status code after my PHP script is finished if it takes longer time to execute

enter image description here

Setting the PHP ini max_execution_time for long time for this script is useless.

<?php
// long script
ini_set("max_execution_time", 3600);// 1 hour
// Apache still responses with the same "Connection: close" header and 500 status code

And I don't want to change the entire Apache TimeOut directive just for those couple of scripts, because if I did, any request will be able to take very long time which makes a scope for DDOS vulnerabilities, is this right?

Is there any way to allow this script only to run longer at the Apache level ?

6
  • Possible duplicate of How to increase apache timeout directive in .htaccess? Commented Apr 2, 2018 at 14:01
  • @rkosegi thank you for the helpful answer in the link, but as I mentioned I can't set the entire server timeout for 1 hour for any request, I only want this specific script to be allowed for longer execution times. Commented Apr 2, 2018 at 14:07
  • The Timeout directive cannot be configured in .htaccess. Its scope is server configuration and virtual host configuration (httpd.apache.org/docs/2.4/mod/core.html#timeout). Also the error you are getting may not be related to the Timeout directive. Please post the contents of your Apache error log file Commented Apr 4, 2018 at 4:14
  • @NadirLatif the last error in the error log is 3 months ago [Tue Jan 02 00:47:30.498460 2018] [:error] [pid 25738:tid 139947671492352] [client 46.152.123.254:64211] sh: /home/*********/public_html../temp/2018-01-02_1514854050.sql: No such file or directory, referer: https://*******************************.com/easy/settings/backups Commented Apr 4, 2018 at 8:34
  • Can you try to enable the error reporting in your php script. You can do this by adding the lines: error_reporting(E_ALL); ini_set("display_errors", '1'); to the top of your php script Commented Apr 5, 2018 at 6:57

1 Answer 1

1

Have you tried PHP's set_time_limit() method?

https://www.php.net/manual/en/function.set-time-limit.php

In addition to setting the initial execution time, the manual says that calling it resets the time expended to zero when called, and starts the counter again to the limit provided.

So if you want to be sure, you could just call set_time_limit(0) (0 == no limit) regularly throughout your script to make sure that you don't ever hit a limit (even though you're setting an infinite limit by passing in 0).

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

1 Comment

Thanks for your time, I will get back to you when I try it, just give me sometime because I'm not using PHP much now.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.