2

I'm trying to use Guzzle to make a post request,send some parameters and a file but when i run the application i get a timeout error

I've tried removing the file from the parameters and the request was sent normally

Error:

Symfony \ Component \ Debug \ Exception \ FatalErrorException (E_UNKNOWN)
Maximum execution time of 60 seconds exceeded

Code that makes the request

$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);

2 Answers2

1

Please Update your Max Execution Time in your php.ini file, also PHP server can cause issue's with post requests try switch to apache or xamp server. For more info: https://laracasts.com/discuss/channels/code-review/file-upload-using-guzzle-client

Aditya Thakur
  • 2,562
  • 2
  • 10
  • 21
0

Perhaps try to update your php.ini file.

  1. Open terminal
  2. type 'php --ini'
  3. Open the loaded configuration

    ini_set('max_execution_time', x)

Replace x with the desired time in seconds (i.e. 120)

TheBurgerShot
  • 1,586
  • 2
  • 11
  • 20