error message that says mysql_real_escape_string() expects parameter 2....

Started by Quexinos, February 23, 2011, 12:03:19 AM

Previous topic - Next topic

Arantor

*facepalm* Damn I'm stupid.

The list() line needs to come before that new block of code... how dumb am I?

That other error is something completely different, usually points to a PHP misconfiguration.

Quexinos

No, you're not stupid, it's fine  ;D
It happens. 

Okay I got the code after the list() line.  But I'm a little confused with all the code being thrown around, is this going to work?

list ($values, $connection) = $db_callback;

if (!is_resource($connection))
{
ob_start();
var_dump(debug_backtrace());
var_dump($connection);
$content = ob_get_contents();
ob_end_clean();
die('Something very bad happened, please advise the administrator of: ' . $content);
}


My BF who knows more than I do about this stuff was very sure I needed the       
$content = ob_get_contents();
in there, but if I just change ob_end_clean to ob_get_clean  will that do the same thing?  I'm assuming it will since I just read "ob_get_clean() essentially executes both ob_get_contents() and ob_end_clean(). "

Also I wonder, if I'm not online and this error happens again, will I still be able to see what's wrong? Or do I have to actually be online for that?

Arantor

Quotein there, but if I just change ob_end_clean to ob_get_clean  will that do the same thing?

As per http://php.net/ob-get-clean

Quoteob_get_clean() essentially executes both ob_get_contents() and ob_end_clean().

Yes, that should work.

QuoteAlso I wonder, if I'm not online and this error happens again, will I still be able to see what's wrong? Or do I have to actually be online for that?

You do have to be online, which is why I had it have 'please advise the administrator of...' line in there. There are ways to have it log somewhere else, but the main method could likely cause worse errors (since the easiest way is to use the trigger_error() function to push it to the error log... which issues a database query)

Quexinos

QuoteYou do have to be online, which is why I had it have 'please advise the administrator of...' line in there. There are ways to have it log somewhere else, but the main method could likely cause worse errors (since the easiest way is to use the trigger_error() function to push it to the error log... which issues a database query)
That's what I was figuring... but I'm about to go to bed (for real) so is it okay if I change that line to "Something very bad happened, please send a message to Dashell with either a screenshot or a copy paste of what this error is:"

or else I'm just afraid they'll say "I got an error" but not remember what it is.

Arantor

Sure you can change it, just remember to avoid using ' in your message is all ;) (since it uses that to indicate the start and end of the text to include)

Quexinos

Hey I got something:  ;D

I'll attach it so it doesn't stretch everything.  My error log isn't filled with errors this time though so I'm not sure if this is anything or not.

Here's hoping.

Arantor

Ah, now that's interesting. For anyone else following the debate in the hopes of finding a resolution, I'll walk you through the trace. Numbers in brackets indicates the backtrace log number, since it's going 'back', the first function is the last in the list.

1. (13) index.php starts, SMF begins, and it drops into smf_main() to determine its final outcome.
2. (12) writeLog() - user is to be logged as being online.
3. (11) DB query to actually log someone as online.
4. (10) Uh oh, there's a problem with the query, so it's bounced to the DB error handler to do something with it.
5. (9) The DB error handler beings to pass it to the fatal error handler; execution cannot continue. Here's where we can see the underlying fault: for some reason, SMF lost connection to MySQL. That usually means there's way too many connections being thrown at MySQL and some are being dropped.

I'll cover off the rest of the trace in case anyone's interested. It will at least explain how we get to the error that we have, even though it's not really the error, it's a symptom that's visible because of the connection already being dropped.

6. (8) The general fatal error handler prepares to display a message to the user, passing to fatal_error_setup_context.
7. (7) OK, we've done everything we have to do to clear up, now it's time to head to the output buffering and actual output content via obExit.
8. (6) Display the page header. (template_header)
9. (5) Process enough details in the theme to be able to display it. (setupThemeContext)
10. (4) Send the page's news to the bbcode parser for display.
11. (3) Send the page's news on to the smiley parser too.
12. (2) Attempt to get the smileys because we haven't got them so far this page execution.
13. (1) It's in the query layer to get the data.
14. (0) It's been passed into the DB code to convert {db_prefix} into the real DB prefix. The connection already failed, getting to this point is simply bound to fail, since the callback needed a connection in order to work, but the connection no longer exists, leading to the original error that started this off.


I've spoken to a few people who've experienced this, and in all cases it seems to be that SMF is being hit hard with a huge burst of traffic and it just causes connections to fail between PHP and MySQL.

Quexinos

So... our forums are just too busy? O_o

I guess... I'd just be surprised if that's all this was, The most I have ever had online was 39, and the first time this happened I only had 11 online.  And how come only those with RC4 and above are having this issue?  Or am I not understanding?

Arantor

QuoteAnd how come only those with RC4 and above are having this issue?  Or am I not understanding?

There have been a total of 10 reports of which I'm aware, of which 4 of those are RC4, 2 are RC5, 3 are RC3, and 1 is 1.1.12, which rules out it being related to RC4, the RC4 patch or RC5. I'm also sure I could get the total list of changes between each version and prove beyond any doubt that the parts changed in the patch do not affect the functions in the backtrace but that would actually be just a waste of my time in doing it.

Also, all of the people are on shared/semi-shared hosting, so it's entirely possible that something else is hitting the server in the meantime and the side consequence is that every request in SMF fails; I can find no evidence at this time to support it being an SMF bug. (And believe me, I'm the first to call the dev team out on serious matters.)

Something is causing MySQL to drop connections; the only things that should ever cause that are: 1. MySQL server bugs, 2. MySQL connector bugs, 3. MySQL being hit so hard it can't keep up with connections so it prunes the oldest first.

Quexinos

QuoteSomething is causing MySQL to drop connections; the only things that should ever cause that are: 1. MySQL server bugs, 2. MySQL connector bugs, 3. MySQL being hit so hard it can't keep up with connections so it prunes the oldest first.
I see... so it's not necessarily that the forums are too busy but something else on the server is.   I wonder if we're all on the same hostgator server or something XD

Well thanks for looking into this, I wonder if I should email the host or something.  Because if I can't have 11 members on my forum, that's just a little ridiculous, invisionfree forums can handle more than that.

You know except for that one time today, I didn't have my error log fill up or anything.  I hope that means whatever it was causing problems has died down.

Arantor

Hostgator are really not known for their performance when it comes to SMF forums. In this case at least one instance is not related to Hostgator having spoken to the host concerned.

Quexinos

QuoteHostgator are really not known for their performance when it comes to SMF forums.
Who would you recommend then?

QuoteIn this case at least one instance is not related to Hostgator having spoken to the host concerned.
Well I didn't mean to say they ALL were hostgators fault.  I've been with them since forever and I love them, but if they can't handle SMF it's either switch forum software or leave hostgator.... I don't really want to do either but I think it'd make more sense to find a more stable server since I can't really afford invision or anything else right now.

Arantor

QuoteWho would you recommend then?

I wouldn't know who to recommend, personally. I've been running everything off my VPS for the last 5 years, and the host I had before that, I wouldn't recommend anyway, biggest bunch of cowboys I've seen in ages.

There is a hosting board here that has a variety of discussions on the subject, you may well find a recommendation in there.

Quotebut if they can't handle SMF it's either switch forum software or leave hostgator....

I wouldn't class this as Hostgator's fault - other hosts have been affected too.

Quexinos

VPS huh? Well Hostgator HAS that...  and the lowest is like $20 a month which isn't too bad.  Maybe I'll just see if I can upgrade.  (Or maybe I'll ask all the others having this problem if they want to get a host with me  ;))

But I do really appreciate you guys looking into this and being so dedicated.  Sorry I was kinda pissy at first, I'm sure you know it's just extremely frustrating when your forum is going on and offline and there doesn't seem to be an answer.  But you found one and that's awesome.  Just another reason I prefer SMF to any other forum out there.

Arantor

I'm personally using a Linode 1024, at $40/month, but it's unmanaged, so I have to configure everything myself (which is exactly what I wanted, I have some funky requirements for the stuff I run)

QuoteSorry I was kinda pissy at first, I'm sure you know it's just extremely frustrating when your forum is going on and offline and there doesn't seem to be an answer.

It's perfectly understandable looking back at it - you want to know why it's messing about, and no-one seems to know what's causing it. Well, I still don't know what's causing it, at the core of it, but I know why it's breaking SMF, if that makes sense. I'd love to know what it is that's actually causing it to drop the connection, what it is that's upsetting MySQL.

Quexinos

Do you think I should talk to my host again and have them take a look?  Maybe there really is someone hammering the SQL. 

Feh and I just realized that hostgator only allows 10GB on their lowest VPS... with all the sites I have I've gone over that already...

Arantor

I would get them to have a look, and see if someone else is hammering MySQL because barring MySQL bugs, that's the only thing that I can see causing this.

charlottezweb

Quote from: Arantor on February 25, 2011, 05:56:47 AM
QuoteAnd how come only those with RC4 and above are having this issue?  Or am I not understanding?

There have been a total of 10 reports of which I'm aware, of which 4 of those are RC4, 2 are RC5, 3 are RC3, and 1 is 1.1.12, which rules out it being related to RC4, the RC4 patch or RC5. I'm also sure I could get the total list of changes between each version and prove beyond any doubt that the parts changed in the patch do not affect the functions in the backtrace but that would actually be just a waste of my time in doing it.

Also, all of the people are on shared/semi-shared hosting, so it's entirely possible that something else is hitting the server in the meantime and the side consequence is that every request in SMF fails; I can find no evidence at this time to support it being an SMF bug. (And believe me, I'm the first to call the dev team out on serious matters.)

Something is causing MySQL to drop connections; the only things that should ever cause that are: 1. MySQL server bugs, 2. MySQL connector bugs, 3. MySQL being hit so hard it can't keep up with connections so it prunes the oldest first.

This is the same issue as this thread correct?

http://www.simplemachines.org/community/index.php?topic=417788

If so, wouldn't all SMF forums on the same server also produce failure logs all at the same time? 

Arantor

Only where the oldest connections are being pruned. It's not all the connections being purges, you'd notice that.

If there were any evidence pointing to it being an SMF bug, I'd happily dive in towards finding its cause, but the debug log is pointing to MySQL dropping the connection, then SMF crashing and burning thereafter. It's not SMF closing it so it's got to be an outside cause.

charlottezweb

It's not adding up based on what I'm seeing. 

So for the access log I sent you with only one connection at that time, does that make any difference?

I guess I'll need to match full server access to one of these timestamps to see but I haven't seen this yet on any other servers and the one having this is one of the most lightly stocked account and usage wise.    Just seems extremely abnormal to me...

Advertisement: