简体   繁体   English

Mysql PHP 在长脚本期间断开连接

[英]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.我遇到了一个问题,我似乎无法弄清楚是否涉及由于数据库连接失败而无法完成的长 php 脚本。

I am using PHP 5.5.25 and MySQL 5.6.23, with the mysqli interface.我使用的是 PHP 5.5.25 和 MySQL 5.6.23,带有 mysqli 接口。

The script uses the TCPDF library to create a PDF of a financial report.该脚本使用 TCPDF 库创建财务报告的 PDF。 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).但是,当数据集变大时(报告可以迭代多个帐户以创建包含所有符合条件的帐户的多页报告)它会在大约 30 秒后失败(不完全是 30,有时会多几秒)邮票)。 It seems to run fine for about 25-35 loops, but more than that causes the problem.它似乎可以正常运行大约 25-35 个循环,但超过这个循环会导致问题。

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.我已将 PHP 设置为相当大量的资源来处理此问题。

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.尽我所能从数据库的一些统计数据中得知,一次只有几个活动连接,所以看起来我没有接近默认设置 150 个最大连接。

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...警告: mysqli::mysqli(): (HY000/2002): 无法在...中分配请求的地址

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.如果没有看到代码,就很难确定,但是一个脚本每秒执行数百个查询持续数十秒,这听起来像是 SQL 和 PHP 逻辑之间的划分没有经过深思熟虑。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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