尝试使用Guzzle 5执行以下代码。
$client = new GuzzleClient(['defaults/headers/User-Agent' => static::$userAgentString]);
$request = $client->createRequest(static::$serviceRequestMethod, $url, $options); // Create signing request.
$signature = new Signature\Signature($this->accessKey, $this->secretKey);
$options = array_merge_recursive($options, ['query' => ['Signature' => $signature->signString($hash)]]);
$request = $client->createRequest(static::$serviceRequestMethod, $url, $options); // Create real request.
$response = $client->send($request);
当我在长时间运行的CLI流程中将此行调用足够次数时,我会将以下错误追溯到行$response = $client->send($request);
cURL error 35: error:02001018:system library:fopen:Too many open files
在点击之后,服务器上的每个其他网页和命令都被打破了相同的"太多的打开文件"错误。
这是堆栈跟踪:
#0 /home/vagrant/code/example.com/vendor/guzzlehttp/guzzle/src/RequestFsm.php(104): GuzzleHttp\Exception\RequestException::wrapException(Object(GuzzleHttp\Message\Request), Object(GuzzleHttp\Ring\Exception\ConnectException))
#1 /home/vagrant/code/example.com/vendor/guzzlehttp/guzzle/src/RequestFsm.php(132): GuzzleHttp\RequestFsm->__invoke(Object(GuzzleHttp\Transaction))
#2 /home/vagrant/code/example.com/vendor/react/promise/src/FulfilledPromise.php(25): GuzzleHttp\RequestFsm->GuzzleHttp\{closure}(Array)
#3 /home/vagrant/code/example.com/vendor/guzzlehttp/ringphp/src/Future/CompletedFutureValue.php(55): React\Promise\FulfilledPromise->then(Object(Closure), NULL, NULL)
#4 /home/vagrant/code/example.com/vendor/guzzlehttp/guzzle/src/Message/FutureResponse.php(43): GuzzleHttp\Ring\Future\CompletedFutureValue->then(Object(Closure), NULL, NULL)
#5 /home/vagrant/code/example.com/vendor/guzzlehttp/guzzle/src/RequestFsm.php(135): GuzzleHttp\Message\FutureResponse::proxy(Object(GuzzleHttp\Ring\Future\CompletedFutureArray), Object(Closure))
#6 /home/vagrant/code/example.com/vendor/guzzlehttp/guzzle/src/Client.php(165): GuzzleHttp\RequestFsm->__invoke(Object(GuzzleHttp\Transaction))
#7 /home/vagrant/code/example.com/app/library/amazon/src/AWS.php(540): GuzzleHttp\Client->send(Object(GuzzleHttp\Message\Request))
我不知道在通过Guzzle发送请求后是否需要显式关闭资源。我在这里遗漏了什么或者这可能是Guzzle中的一个错误吗?
答案 0 :(得分:1)
这不是Guzzle或MailGun的问题,而是与您特定的库实现有关。实际上,您通过长时间运行(打开)请求来达到底层操作系统(libcurl,openssl和fopen)的限制。
根据libcurl errors错误35表示SSL / TLS握手出错。
根据各种谷歌引用错误:02001018表示openssl无法访问(或者更确切地说)读取证书文件。
您可以使用ulimit查看和修改各种系统范围资源的限制。
您还可以使用lsof查看打开的文件。
解决您的问题: