News:

Bored?  Looking to kill some time?  Want to chat with other SMF users?  Join us in IRC chat or Discord

Main Menu

Search error: Sorry, SMF was unable to connect to the database

Started by spiros, April 13, 2017, 04:00:45 AM

Previous topic - Next topic

spiros

I get this error sometimes when searching (and it is quite slow although I use Sphinx). For example with this search:

Connection Problems

Sorry, SMF was unable to connect to the database. This may be caused by the server being busy. Please try again later.
Warning: Cannot modify header information - headers already sent by (output started at ../public_html/forum/Sources/Errors.php:423) in ../public_html/forum/Sources/Errors.php on line 354

Warning: Cannot modify header information - headers already sent by (output started at ../public_html/forum/Sources/Errors.php:423) in ../public_html/forum/Sources/Errors.php on line 355

Warning: Cannot modify header information - headers already sent by (output started at ../public_html/forum/Sources/Errors.php:423) in ../public_html/forum/Sources/Errors.php on line 356

Warning: Cannot modify header information - headers already sent by (output started at ../public_html/forum/Sources/Errors.php:423) in ../public_html/forum/Sources/Errors.php on line 359

Warning: Cannot modify header information - headers already sent by (output started at ../public_html/forum/Sources/Errors.php:423) in ../public_html/forum/Sources/Errors.php on line 360

Warning: Cannot modify header information - headers already sent by (output started at ../public_html/forum/Sources/Errors.php:423) in ../public_html/forum/Sources/Errors.php on line 361
Connection Problems

Sorry, SMF was unable to connect to the database. This may be caused by the server being busy. Please try again later.

richardwbb

I'm not running 2.0.13 and my Errors.template.php stops ~ 200.

But I can tell you, that presumably Errors.template.php [your], is doing something unexpected by 'something' [something which mostly isn't smf itself, did you install a modification maybe].

So you might want to post the [ code] [/ code] [the hash icon just above], from Errors.template.php starting from rule 423, go up to the first remark, then all the way down to the next one, if it isn't hundreds of lines [some parts of smf code are, really, really long for a reason, but this isn't to be expected here]. Maybe someone can tell you something.

And all in all, a 'generic php'; 'Warning: Cannot modify header information' means the opposite, it has already posted the headers, and somewhere else in the code those headers are posted again, but the first code wasn't finished yet [correct me if I am wrong, but I am in the ballpark], it means [without starting a long topic, but keeping things simple]; the smf software didn't get around to connect to the database, since the php module running on the [presumably] Apache web server doesn't allow it. And I stop here, I've seen this error quite a few times with some of my own 'hobbyscripting', non smf related, and php errors can be incomplete, the opposite, and send you in to the woods. Here is an interesting link [but quickly found by me]; https://www.tutorialspoint.com/http/http_header_fields.htm Oh, the php software can't modify headers that are already sent by the [Apache] webserver, I don't remember why I had the opposite. Not RTFM'ing here, it get's better over time. HTTP headers are necessary and not evil, but is code sent before the first character can be displayed [and smf does something in php memory I haven't figured out yet], think of a text file, it can contain a header, those header files aren't displayed by the viewer. And I HTH. To see [http] headers in action you might want to get a 'http header viewer plugin for Chrome or Firefox', it can make your rating with search engines better, but that is another story.
If my post in this topic looks ambiguous to you, then I'm with Murphy's law and General Stupidity. In other words, trial and error.

spiros

Thank you :)
423 was </html>';

echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta name="robots" content="noindex" />
<title>Connection Problems</title>
</head>
<body>
<h3>Connection Problems</h3>
Sorry, SMF was unable to connect to the database.  This may be caused by the server being busy.  Please try again later.
</body>
</html>';

die;
}

?>

richardwbb

I'm not really getting what '423' is meaning. I assumed it was 'line 423'. I've clicked your link 'search' and everything seems to be working now. For the error line, I wonder how you were able to make sure for your self it must be that part. But maybe you got me there, because I don't know. I do know, sometimes errorlines shown by php are higher then the length of the code. A dev would be able to give some insight here. Personally I've learned that chances are something else is going wrong somewhere and I give up. However, does smf still display connection errors or is it gone now, and why.
If my post in this topic looks ambiguous to you, then I'm with Murphy's law and General Stupidity. In other words, trial and error.

spiros

This is the offensive code from line 353 (354 is the first mention in the error):

// Don't cache this page!
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
header('Cache-Control: no-cache');

// Send the right error codes.
header('HTTP/1.1 503 Service Temporarily Unavailable');
header('Status: 503 Service Temporarily Unavailable');
header('Retry-After: 3600');

richardwbb

Ah yes, I see now, the colon means at the 423'th place and the linerule is 354.

It looks a bit ambigous to me, but, that is just me and I have that sometimes. However, you might want to give it a 'shotgun debugging' try. So don't do this with the live server of course. There are already headers sent from 'somewhere before' [and that could be anything I'm a fraid], but it can also easy; first remove the lines of of offensive code and reproduce [again; your link looked okay with my browser], if you omit the first three headers, try this, and even if that works I recommend trying to omit the second set of three headers. I'm in the blind here, that it might make the problem go away [which I doubt], this doesn't mean it will generate a 'new' problem with something else. Also, omit all the six headers. And to end my reply, I could share some .htaccess cache control that made my website notable faster [tested with a reliable testing service on the internet I forgot the link of, and that wouldn't make this problem go away, but I just prefer .htaccess, smf is made for the general public, if you are savvy on something, they way to look at 'things' can become different]

I hope you can make heads or tails of this what I wrote. And do not forget, if someone like Illori is saying something else, you should believe that.
If my post in this topic looks ambiguous to you, then I'm with Murphy's law and General Stupidity. In other words, trial and error.

spiros

Thank you for your advice. Well, the point is this issue is intermittent :)
Yes, speeding up is an issue, please share if you want. The search results are quite slow, despite Sphinx.

richardwbb

For starters, if you are able, to make 'intermittent' go to 'reproducible', it should be able to tell you what part [of the whole smf 'system', can not be responsible].

Are you aware what headers are, for firefox and most probably chrome too, there is a plugin to be able to see them and with 'wget' for linux and I wouldn't be surprised it has been ported to windows, it is a one-liner.

And for the speed issue, here is some .htaccess with 100% 'you are on your own' agreement, haha. Seriously, note that chances your first problem goes away are close to zero and it might produce an unexpected result, however, I'm running this for a couple of months now. Notice the scrollbar next to this quite long part of .htaccess code and import it block by block is a wise choice.
#[http://www.askapache.com/htaccess/apache-speed-compression/]
<IfModule mod_headers.c>
Header unset ETag
FileETag None
Header set Cache-Control "public, no-transform, max-age=0, no-cache, no-store, must-revalidate"
#[Please don't turn off ETags and Last-Modified headers for your .html files, leave one of them ON. (I use Last-Modified for .html).]
<FilesMatch "\.(ico|jpg|jpeg|png|gif|js|css)$">
Header unset Last-Modified
</FilesMatch>
</IfModule>



<IfModule mod_gzip.c>
#[https://www.gavick.com/blog/speed-website-simple-htaccess-tricks]
mod_gzip_on Yes mod_gzip_dechunk Yes
mod_gzip_item_include file .(html?|txt|css|js|php|pl)$
mod_gzip_item_include handler ^cgi-script$
mod_gzip_item_include mime ^text/.*
mod_gzip_item_include mime ^application/x-javascript.*
mod_gzip_item_exclude mime ^image/.*
rspheader ^Content-Encoding:.*gzip.*
</IfModule>



# BEGIN Expire headers
#[https://www.gavick.com/blog/speed-website-simple-htaccess-tricks]
<ifModule mod_expires.c>
ExpiresActive On ExpiresDefault "access plus 5 seconds"
ExpiresByType image/x-icon "access plus 2592000 seconds"
ExpiresByType image/jpeg "access plus 2592000 seconds"
ExpiresByType image/png "access plus 2592000 seconds"
ExpiresByType image/gif "access plus 2592000 seconds"
ExpiresByType application/x-shockwave-flash "access plus 2592000 seconds"
ExpiresByType text/css "access plus 604800 seconds"
ExpiresByType text/javascript "access plus 216000 seconds"
ExpiresByType application/javascript "access plus 216000 seconds"
ExpiresByType application/x-javascript "access plus 216000 seconds"
ExpiresByType text/html "access plus 600 seconds"
ExpiresByType application/xhtml+xml "access plus 600 seconds"
</ifModule>
# END Expire headers


For the speeding things up, -some- knowledge about mysql would be great. The topic that helped me [but really, not every tip in there is truly vandal proof, so you have been warned]; 'https://www.simplemachines.org/community/index.php?topic=293441.0'; Also, there is another topic I'm sure you can find now, they look similar, I needed both. And, continue reading before starting with this tip.

And for the database itself, get familiar with phpmyadmin, sort the database tables on size, read their names, and delete from there. The former tip will be a guide. -it really is possible to make the database go in 'bork mode', and I have no experience with 'importing smf_settings' and 'smf_messages' with the personal messages too; all I know, I would still be missing so many things, it isn't a proper way for me to fix a database with a former Site Admin, that did not have the time and experience to dive in to things like this, he now went to a 'ict school', but unfortunaly I lost contact with him. To make it clearer; a inherited forum gives me uncertainty, that is how it goes.

Let me know how it went for you. There must be more for me to advise, but I'm at this moment not able to 'grep' this from my 'notes all over the place', haha.
If my post in this topic looks ambiguous to you, then I'm with Murphy's law and General Stupidity. In other words, trial and error.

spiros

I had implemented most the SMF speed suggestions long time ago :)

Your code appears to have had significant effect on site loading speed AND Sphinx search, thank you!

Arantor

Possibly because it's telling the browser to keep pages cached for up to 10 minutes without even needing to roundtrip to the server to see if they've updated.

Advertisement: