简体   繁体   中英

PHP Guzzle gives empty body stream with empty contents on forked process, how i change the uri of the stream wrapper to a custom one?

I'm working on a multi-processed task (5 childs) that at some point of code make requests to an API, takes the data, normalise and persist to database.

I'm having a problem with guzzle on this environment because sometimes i have a http 200 response but the content of the body stream comes empty and look like it because the guzzle uses by default the uri "php://temp" that seems to generate a conflict on multi-processed tasks. I tested the requests where this happens and the request works on single process. Bellow the dump of the body of response:

class GuzzleHttp\Psr7\Stream#474 (7) {
  private $stream =>
  resource(687) of type (stream)
  private $size =>
  NULL
  private $seekable =>
  bool(true)
  private $readable =>
  bool(true)
  private $writable =>
  bool(true)
  private $uri =>
  string(10) "php://temp"
  private $customMetadata =>
  array(0) {
  }
}

There is a way to change the Guzzle Stream Wrapper to a custom one to avoid conflicts ?

Was my mistake, once we read the body stream if we need to reuse we need to rewind the stream to read it again.

I also make some changes like create a new instance on each child instead of use the copy of guzzle client from the parent.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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