我一直在挠我的脑袋,试图找出是什么导致我的脚本中的间歇性错误。错误是:SQLSTATE [HY000]:一般错误:2006 MySQL服务器已经消失。间歇性的MySQL服务器已经消失了错误
下面的脚本是一个函数的一部分,该函数执行curl,从JSON响应中获取一些值,然后将它们写入表中。我会说80%的时间工作正常,然后另外20%我得到服务器消失的错误。我一直无法确定导致错误的任何趋势,这似乎是随机的。任何想法,为什么我可能会得到这个错误?感谢您检查了这一点
...
//post via cURL
$ch = curl_init($url);
$timeout = 500;
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $myvars);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$this->response = curl_exec($ch);
$this->json_decoded = json_decode($this->response);
$this->full = print_r($this->json_decoded, true);
$client_leadid = $this->json_decoded->Parameters->lead_id;
$client_status = $this->json_decoded->Status;
$length = curl_getinfo($ch);
curl_close($ch);
//record in DB
$insert = $this->full.' | '.$url.' | '.$myvars.' | '.$this->date . ' | Time Taken: '.$length['total_time'];
$db->exec("UPDATE table SET client_resp = '$insert' WHERE global_id = '$this->leadid' LIMIT 1");
$db->exec("UPDATE table SET client_leadid = '$client_leadid' WHERE global_id = '$this->leadid' LIMIT 1");
你可以在MySQL错误日志读什么? – Jocelyn
你可能会想找到找到的原因清单[这里](http://dev.mysql.com/doc/refman/5.0/en/gone-away.html)。 – Josh
您可以将查询数减少50%,这可能会对您所面对的renadom角色产生积极影响。快乐的调试,因为你迄今共享的内容不是问题,而是猜测的邀请。当工作/停止工作时,网络连接会发生什么情况。你有没有监视这些?怎么样的错误日志?服务器负载如何?实际上,请以纯文本形式提供查询,而不是PHP代码。 – hakre