简体   繁体   中英

Mysql PHP dropping connection during long script

I am having a problem that I can't seem to figure out involving a long php script that does not complete due to a Database connection failure.

I am using PHP 5.5.25 and MySQL 5.6.23, with the mysqli interface.

The script uses the TCPDF library to create a PDF of a financial report. Overall it runs fine. However, when the data set gets large (the report can iterate over numerous accounts to create a multiple page report with all the accounts that match criteria) it will fail after about 30 seconds (not exactly 30, sometimes a couple of seconds more by time stamps). It seems to run fine for about 25-35 loops, but more than that causes the problem.

I don't think its an issue of timing out (although it certainly could be). I have PHP set to fairly generous amounts of resources to process this.

max_execution_time = 600 
memory_limit = 2048M

The script does hit the DB pretty hard with hundreds of queries per second. As best as I can tell from some stats from the DB, there are only a couple of active connections at a time so it does not appear that the I am anywhere close to the default setting of 150 max connections.

This is the error I get when it eventually fails with a large data set.

Warning: mysqli::mysqli(): (HY000/2002): Can't assign requested address in...

Fatal error: Database connection failed: Can't assign requested address in...

Does anyone have any suggestions on what may be causing the script to eventually not be able to connect to the DB and fail to complete? I've tried searching for some answers but pretty much everything I have found so far about Database Connection failures are not being able to connect at all, rather than not being able to connect midway through a large script.

Thanks in advance for any advice.

I don't think it's an issue of timing out

You should know .

It seems strange that the issue is arising so long after the start of execution. Would it have been so hard to check what the timeout is? To try changing it? To add some logging to your code?

The other thing you should be checking is whether the script is opening a single connection and reusing it or constantly opening new connections.

Without seeing the code, its hard to say for sure, but a single script executing hundreds of queries per second for tens of seconds sounds like the split between SQL and PHP logic has been very poorly thought out.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM