尝试上传文件时请求超时
Request timing out when trying to upload file
我正在尝试使用 Guzzle 发出 post 请求,发送一些参数和一个文件,但是当我 运行 应用程序时,我收到超时错误
我已经尝试从参数中删除文件并且请求正常发送
错误:
Symfony \ Component \ Debug \ Exception \ FatalErrorException (E_UNKNOWN)
Maximum execution time of 60 seconds exceeded
发出请求的代码
$client = new GuzzleHttp\Client();
$res = $client->sendAsync('post', 'http://api.ocr.space/Parse/Image',[
'headers' => [
'apikey' => 'helloworld',
],
'multipart' => [
[
'name' => 'language',
'contents' => 'por',
],
[
'name' => 'filetype',
'contents' => 'png',
],
[
'name' => 'file',
'contents' => fopen(asset('/public/Screenshot_2.png'), 'r'),
'filename' => 'file.png'
]
]
]);
$content = json_decode($res->getBody(), true);
dd($content);
也许尝试更新您的 php.ini 文件。
- 打开终端
- 输入'php --ini'
打开加载的配置
ini_set('max_execution_time', x)
将 x 替换为所需的时间(以秒为单位)(即 120)
请在您的 php.ini 文件中更新您的最大执行时间,另外 PHP 服务器可能会导致 post 请求出现问题,请尝试切换到 apache 或 xamp 服务器。更多信息:https://laracasts.com/discuss/channels/code-review/file-upload-using-guzzle-client
我正在尝试使用 Guzzle 发出 post 请求,发送一些参数和一个文件,但是当我 运行 应用程序时,我收到超时错误
我已经尝试从参数中删除文件并且请求正常发送
错误:
Symfony \ Component \ Debug \ Exception \ FatalErrorException (E_UNKNOWN)
Maximum execution time of 60 seconds exceeded
发出请求的代码
$client = new GuzzleHttp\Client();
$res = $client->sendAsync('post', 'http://api.ocr.space/Parse/Image',[
'headers' => [
'apikey' => 'helloworld',
],
'multipart' => [
[
'name' => 'language',
'contents' => 'por',
],
[
'name' => 'filetype',
'contents' => 'png',
],
[
'name' => 'file',
'contents' => fopen(asset('/public/Screenshot_2.png'), 'r'),
'filename' => 'file.png'
]
]
]);
$content = json_decode($res->getBody(), true);
dd($content);
也许尝试更新您的 php.ini 文件。
- 打开终端
- 输入'php --ini'
打开加载的配置
ini_set('max_execution_time', x)
将 x 替换为所需的时间(以秒为单位)(即 120)
请在您的 php.ini 文件中更新您的最大执行时间,另外 PHP 服务器可能会导致 post 请求出现问题,请尝试切换到 apache 或 xamp 服务器。更多信息:https://laracasts.com/discuss/channels/code-review/file-upload-using-guzzle-client