500 Internal Server error with csv reader script - php

I am working on php script which downloads and reads csv file and imports things to database. But I have a problem: when this script is working for a long time, I will get Error 500 - Internal Server Error. I don't know why, but server have set execution time on 90 sec, but my script is working longer time (about 6 minutes) and then I get this error.
When I got execution time error it's ok, because I can catch it with register_shutdown_function() and make another instance with cUrl, but this error is uncatchable for me.
Have anyone any clue how to catch it or make execution time error working ?
I tried set_time_limit(), but it's not working too, because server is in safe mode. And it's web hosting, so I can't change php.ini or something like this.
Thanks for any answer

Related

Getting 500 - Internal server error when page taking more time to execute

I have one website in Yii framework.
It was working fine till few days but since few days sometimes I am getting
500 - Internal server error. There is a problem with the resource you are looking for, and it cannot be displayed.
This error occurs when there is more data load in page.
If I am on simple page where there is no need to get more data in page then it is working fine but when I am uploading or downloading or need more time to get data then mostly I am getting this error.
I have Windows server.
Can anybody guide me how can i solve this error?
You should check the webserver and php error logs, most probably is configuration problem
memory_limit
max_execution_time
upload_max_filesize
check http://php.net/manual/en/ini.core.php

http error 500 every day only in a specific time of the day

I have the 500 http errors every day in the time between 1:00 - 2:00 and only at this time.
My web it's in a shared server of 1and1 and I think it should be some problem with a maintenance process scheduled at this time because the error always appears at the same time (more or less) and the rest of the day all it's ok.
I've contacted with 1and1 and they are investigating it but I don't trust on them.
I've seen in the log that during this problematic period the http calls to some image for example it works (return code 200). But the calls to a php file with a mySql query fails with 500.
Could be some problem with too muchs access to databases? is the 500 error possible in this cases?
In this scripts I access to a file located in a protected folder (rwx------) to take the user and password. I don't know if it matters.
What can I do to try to know more about the problem?
Any idea?
Thank you.
Some causes of 500 Internal Server Errors
1.File permissons set incorrectly.
2.Coding errors in the .htaccess file.
Analyse the logs which should give further information about the error.

Swiftmailer crashes without php error

I have a web app that allows the user to upload a pdf and it will then email it to us via swiftmailer. With some pdfs, the process fails.
I can verify that it crashes the php script, yet returns no php error. There's a 500 error from the server, but normally if there's a 500 error, php has a log of what the error was.
I have also verified that it crashes at the
$mailer->send($message);
line
Oddly, only some pdfs crash it, and those same pdfs work fine on the development server with identical code.
What could be causing php to crash without an error message?
After running several tests, I found that error logging was happening some of the time, but not others. I didn't figure out why that was so, however, I tried renaming the php-errors.log file so php would start with a new, fresh log file, and now errors are getting logged properly. I don't know why that worked, but I'll take it.
FYI, I've run into two things that can cause a PHP crash without an error message:
Script timeouts - A timeout may prevent an error message from being returned; in my particular case the script was waiting for an SMTP response when the timeout happened, which may have been why I didn't get a timeout message. Try changing your max_execution_time value in php.ini to 300 (5 minutes) and see if you can get an actual error message.
Folder permissions - I've encountered a case where insufficient folder permissions resulted in the script just halting without providing an error.
In the case of 2, I wrapped a try/catch clause around the line that was causing the halt, and I finally got an Exception to show up explaining about the permissions problem. That may be worth trying as a general response to silent crashes.

PHP task terminated but no error condition raised

A PHP script is using the ZipArchive class and is potentially long running.
Since it is dying silently but writing a partial zip file, I wrapped error_log() statements around the $zip->close(). (ini_set sets error logging to a file and E_ALL just before this code)
error_log("calling zip->close()");
$rc = $zip->close();
error_log("zip->close() returned $rc");
The logging file shows the first error_log, but never the second.
A unix top command shows the process running for a total CPU time of c. 2.5 minutes before it goes defunct.
I have also tried trapping the error with set_error_handler(), and the handler using error_log() to record the catch. But nothing shows up in the log file.
I'm assuming the process is being bounced, maybe by Apache (I have no control over Apache or PHP).
My question is: why can't I see this error in the file being used by error_log?
Thanks for the suggestions for circumventing the problem, but my question remains:
Why can't I see this error in the log? Or why can't I catch this error via set_error_handler()?
set_time_limit(0);
0 = Indefinitely

Error 101 (net::ERR_CONNECTION_RESET): In PHP

I am trying to upload an audio to server using php. I am getting this error. I understood the problem is due to timeout. But how to change on thew server??
set_time_limit(0)
This will set the time limit to nothing (aka no time limit)

Categories