500 Internal Server Error or very slow result



I have the next php script and, this always work very well (loading time before 1 second) but about two or three days to now, I get the 500 Internal Server Error or this simple function spend more than 20 seconds to load.

My dreamhost server is “Burke”, I use mysqli to connect to the database.
In error.log I get: Premature end of script headers: menu.php…

Who can I put this working? Move to another webhost?
Please help me!!!

The php script is:

<?php header("Content-Type: text/xml"); ini_set('display_errors','On'); ini_set('display_startup_errors','On'); error_reporting(E_ALL & ~E_NOTICE); // db properties to mysqli class define ("DB_SERVER", 'mysql.domain.com'); define ("DB_NAME", 'db_name'); define ("DB_USER", 'db_user'); define ("DB_PASSWORD", 'db_pass'); include_once 'library/mysql.php'; // simple mysqli class function getRows ($sql){ $data = false; $myDB = new MySQL(); $myDB->Query($sql); if ($myDB->TotalRows() > 0) { while( $row = $myDB->FetchArray() ) { $data[] = $row; } } $myDB->Close(); return $data; } function mostraMenuXML($pid=0, $isMulti=false) { if ( $isMulti ) $menu = getRows("SELECT id, titulo FROM artigos WHERE menuid = $pid ORDER BY ordem, data"); else $menu = getRows("SELECT id, nome, publicado, tipo FROM menu WHERE parentid = $pid ORDER BY ordem"); if ( !$menu ) return ""; if ($pid==0 ) $xml = "\n\n"; else $xml = ""; if ( $isMulti ) { foreach ($menu as $item) { $xml .= "\n"; $xml .= "\n"; } } else { foreach ($menu as $item){ $xml .= "\n"; if ( $item['id'] != $pid ) $xml .= mostraMenuXML($item['id'], $isMulti); $xml .= "\n"; } } if ($pid==0 ) $xml .= "\n"; return $xml; } echo mostraMenuXML(); ?>


every time I’ve had an issue like this with my picture gallery or something similar, it’s always due to extremely high load on the server. Have you checked the loads on your server? I’ve always just opened a support ticket and pasted the uptime results into it for the admins to find the offending CPU hog and take care of it.


How can I check the loads on my server?

Thanks for the answer.


login via SSH and run “uptime” without quotes, there will be a set of three numbers like this:

[walsh]$ uptime
11:03:00 up 3 days, 7:00, 4 users, load average: 4.37, 5.53, 5.01


I get:

[burke]$ uptime
11:41:05 up 4 days, 22:47, 6 users, load average: 10.70, 9.64, 9.49

Is this good? The php keep spend more than 20 seconds to load and sometimes give error 500…


That’s not good. It should be below 5. Submit a ticket to support. The might just say it’s ok, but keep nagging them every time you get 500s and the load is 10 or more.



Thanks all, for the advices.

I will submit a new ticket.


FYI, i’ve had a ticket outstanding for more than a day now, requesting a callback, and getting nothing.