phpapacheinternal-server-errorhttp-status-code-500external-dependencies

500 Internal Server Error depending on external loaded files?


I have an 500 Internal Server Error and most likely think in my case that loading external files is my issue here. In my status bar I got the message Waiting for available sockets... before that happened.

I found this information as I googled:

PHP CODING TIMING OUT

If your PHP script makes external network connections, the connections may time out. If too many connections are attempted and time out, this will cause a "500 Internal Server Error." To prevent these time outs and errors, you'll want to make sure that PHP scripts be coded with some timeout rules. Typically, however, catching a timeout error when connecting to a database or externally to remote resources (example: RSS feeds) are difficult. They, in effect, freeze the script from continuing to run.

Removing any external connections can increase both the performance of your website and decrease the chances of you receiving a "500 Internal Server Error."

1) I dynamically generate/load css and js files from my webserver (*.php files). So I don't know if the modern browser actually caches this or can't cache this at all and handles it as a new request every page load? Because PHP generates this depending on parameters given to tell which css/js should be loaded. Is this even THE issue or problem that can cause this 500 Internal Server Error?

2) What Chrome extension can you recommend to track and debug all network data? What tools in general except Chrome DevTools could help me?

3) The quoted text says I have to take care of timeouts. What are significant sources I should check? Could ajax requests or maybe php Sessions be the issue?

4) Most importantly: How can I fix this error? The domain can be navigated at www.vaymodels.com if this helps to mention. I can't open it with any browser and not even with my Smartphone (disabled WiFi). Maybe someone of you could open it and view the page source.

Also it is worth to mention that this behaviour had just begun in the last few days. I constantly uploaded files as I worked on my website and refreshed the domain a lot and randomly it didnt load at all for 5-10min. But it could be reached without the 500 error after that. Now it seems unreachable.

Edit: My webhoster just told me they updated my FPM limit from 15 to 30. There were too many php processes he said. Could this be caused by mysql queries I'm executing through a file that is loaded via cronjob or what could be those processes I should look for and is most likely the issue?


Solution

  • You should first understand what scripts causes the 500 error. You may have a look at the error logs or you might add at the top of the suspicious scripts:

    ini_set("display_errors",1);
    error_reporting(E_ALL);
    

    this should help you to understand where the problem is, but might also disrupt the output so be careful if you use it in production environments.

    About the caching of js and css resources: you can instruct apache to tell the browser to use a cached copy of the file using some directives in the.htaccess file like:

    <IfModule mod_expires.c>
    ExpiresActive on
    ExpiresByType text/css                  "access plus 1 month"
    ExpiresByType application/javascript    "access plus 1 month"
    ExpiresByType text/javascript           "access plus 1 month"
    
    <IfModule mod_headers.c>
    Header append Cache-Control "public"
    </IfModule>
    
    </IfModule>
    

    Also keep in mind that such expiration limits may be good in a production environment where you are supposed not to change them often.

    Hope that helped.