There is a PHP script launched from the browser, the execution time is several hours.

About 20 minutes after launch, the 500 Internal Server Error crashes in the browser, the script itself continues to work, everything is completed successfully and only the last line is not executed (writing to the log file).

max_execution_time set to 360000 . The script thus eats 40-50% of the processor.

What could be the problem?

  • And where is max_execution_time set? Have you set via php.ini or via .htaccess? - cy6erGn0m
  • 7
    o_0. Maybe in this case it is better not to do it in the browser? - kirelagin
  • Maybe it makes sense every 19 minutes to send browsers some HTML comments? - Viktor
  • @kirelagin such questions are rarely relevant for the PHP public :) - cy6erGn0m
  • cy6erGn0m, in php.ini - e5f

4 answers 4

Try to dig in the direction of technology AJAX. On the HTML page, make an AJAX request using JS, let the PHP script on the server give any response. JS on HTML will receive the answer itself and display it on the HTML page.

Thus, you will be 100% aware of the status of the execution of the PHP script. (Well ... at least you will be aware of its implementation).

Now on the previous comments:

And where is max_execution_time set? Have you set via php.ini or via .htaccess?

The browser has a time limit for waiting for a response from the server. So it's not about these variables. Moreover, the person says that the script is fully executed.

@kirelagin questions like this are rarely relevant for a PHP public :)

In vain do you think so :) ... As a developer, I have already come across this and often come across to this day :)

Maybe it makes sense every 19 minutes to send browsers some HTML comments?

In any case, PHP generates HTML content. If you send the code in 19 minutes, not the fact that it will be seen on the side.

My result is: AJAX to help you :)

PS Googling on ajax.js. You can also do with jQuery.

    Most likely, your web server on which the script is running is backend to another web server. A good example is nginx + apache. The 500th error arises from the fact that when you make a request, nginx starts processing it, sees dynamic content that Apache has to process, redirects the request to it and waits for it to finish, or after a timeout in in your case, - 20 min, gives the user a 500th error. In this case, the instructions max_execution_time will not help, because they are directed to the Apache, and not to nginx.

    PS you can solve the problem:

    1. run the script as cgi on behalf of nginx,
    2. remove timeout when transferring via nginx.

    PPS As for writing to the log file, I would advise you to intercept the script error stream and write it to the file, most likely, there will be some kind of error, for example, an error in accessing the file.

    • Horror, why such difficulties, which by 99.9% will not give any effect? :))) ... You, Sasha Mamaev, apparently, gave programming courses to Hindus)))) * Either they studied with Hindus :) - Asisyakin
    • But I do not understand ... if the person said that the script! EXECUTED!, Then what could be a "file access error"? :) Author, read above ... here without Ajax nowhere :) - Asiskin
    • to Asisyaskin 1) these difficulties are the right way out in the context of this problem, and what you write about Ajax is what the Indian code really is. What will return your Ajax, if the script throughout the work opens the socket and reads from it ?? And how much will it be laboriously rewritten? - Alex Mamaev
    • 2) about access to the file, here I already begin to doubt my professional abilities, if the script is executed, it’s not at all the fact that it has access to the log file, and if the script runs from the command line and writes to the log file, it only means One thing is that when it was launched from a given user, he had access to write to the file. In the case when they run on behalf of the web server, PHP does not have privileges to write to the file and simply cannot write to it ... PS author set the correct rights to access the log file! - Alex Mamaev
    • No, it’s just Apache ... - e5f

    Send the actions performed to the browser, for this there were php functions that allowed you to send content on the go, which I do not remember exactly - see the documentation. Try also to increase the time to wait for a response. Try running the script as a separate process and not through a web server.

      Well, by the way, yes, do every 19 minutes:

       print " "; flush(); 

      and maybe help.