guzzle
Guzzle, an extensible PHP HTTP client
Guzzle, PHP HTTP client — Guzzle Documentation
How can I autoload Guzzle in Laravel 4?
I am encountering the following error when I try to create a new GuzzleHttp/Client:
Symfony \ Component \ Debug \ Exception \ FatalErrorException
Class 'GuzzleHttp\Client' not found
I have the following set up in my composer.json autoload section:
autoload: {
"psr-0": {
"Guzzle\\": "src/"
}
}
Source: (StackOverflow)
I am making following request which resulted empty reply from server.
Originate server : AWS ec2 / PHP 5.4 / Guzzle
Remote server : AWS ec2 through elb
CURL info :{
"url":"https:\/\/xxx\/xxx",
"content_type":null,
"http_code":0,
"header_size":0,
"request_size":5292,
"filetime":-1,
"ssl_verify_result":0,
"redirect_count":0,
"total_time":120.987057,
"namelookup_time":0.000277,
"connect_time":0.001504,
"pretransfer_time":0.014271,
"size_upload":2430,
"size_download":0,
"speed_download":0,
"speed_upload":20,
"download_content_length":-1,
"upload_content_length":2430,
"starttransfer_time":60.998147,
"redirect_time":59.988895,
"certinfo":[],
"primary_ip":"54.169.126.111",
"primary_port":443,
"local_ip":"192.168.2.111",
"local_port":39522,
"redirect_url":""
}
CURL error : [curl] 52: Empty reply from server [url] https:\/\/xxx\/xxx
Pls note that this does not happen all the time.
It seems like the request has not even reach the destination(elb) since there was no logs relate to the request
1. Is the issue with originate server or remote server ?
2. "starttransfer_time":60.998147 Could this be the root cause ?
Solutions,workarounds,suggestions are welcome.Thanks!
Source: (StackOverflow)
Guzzle includes a simple NodeJS server for testing, and I am using that to mock my backend. The server contains a getReceivedRequests
method which returns a list of all the requests that it had received, and I am trying to inspect the requests to make sure my program is sending them correctly.
For GET
requests it's easy enough. Looking at the Request
class, I can get the query parameters and assert on them.
The question comes when I am trying to inspect a PUT
request. Looking at the Request
class there seems to be no way for me to get its payload. In fact I don't even know where the payload is stored in the object, as there is no private fields indicated as such.
Is there anyway I can assert on the payload of a guzzle request?
Source: (StackOverflow)
How make post request with GuzzleHttp( version 5.0 ).
I am trying do the following and getting error
$client = new \GuzzleHttp\Client();
$client->post(
'http://www.example.com/user/create',
array(
'email' => 'test@gmail.com',
'name' => 'Test user',
'password' => 'testpassword'
)
);
PHP Fatal error: Uncaught exception 'InvalidArgumentException' with message 'No method can handle the email config key'
Source: (StackOverflow)
I'm trying to use Guzzle, but I'm getting the following fatal error:
Fatal error: Class 'GuzzleHttp\ClientInterface' not found in /var/www/myapp/vendor/guzzlehttp/guzzle/src/functions.php on line 13
I'm autoloading with composer autoloader:
require 'vendor/autoload.php';
use Guzzle\Http\Client;
$client = new Client();
$requests = Array(
$client->createRequest('GET', 'ams1.myapp.com:8080/api/ffmpeg_make_snapshots.php'),
$client->createRequest('GET', 'ams2.myapp.com:8080/api/ffmpeg_make_snapshots.php'),
$client->createRequest('GET', 'ams3.myapp.com:8080/api/ffmpeg_make_snapshots.php')
);
$client->sendAll($requests);
What is happening?
EDIT
My composer.json:
{
"require": {
"guzzlehttp/guzzle": "~4"
}
}
EDIT 2
My composer.lock
{
"_readme": [
"This file locks the dependencies of your project to a known state",
"Read more about it at http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file"
],
"hash": "33c003b6e3e2dc0144146f9b652a6719",
"packages": [
{
"name": "guzzlehttp/guzzle",
"version": "4.0.0",
"source": {
"type": "git",
"url": "https://github.com/guzzle/guzzle.git",
"reference": "4063f08ca434efac12bf7a3db0d370b1c451345b"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/guzzle/guzzle/zipball/4063f08ca434efac12bf7a3db0d370b1c451345b",
"reference": "4063f08ca434efac12bf7a3db0d370b1c451345b",
"shasum": ""
},
"require": {
"guzzlehttp/streams": "1.*",
"php": ">=5.4.0"
},
"require-dev": {
"ext-curl": "*",
"phpunit/phpunit": "4.*",
"psr/log": "~1"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "4.0.x-dev"
}
},
"autoload": {
"psr-4": {
"GuzzleHttp\\": "src/"
},
"files": [
"src/functions.php"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Michael Dowling",
"email": "mtdowling@gmail.com",
"homepage": "https://github.com/mtdowling"
}
],
"description": "Guzzle is a PHP HTTP client library and framework for building RESTful web service clients",
"homepage": "http://guzzlephp.org/",
"keywords": [
"client",
"curl",
"framework",
"http",
"http client",
"rest",
"web service"
],
"time": "2014-03-29 23:11:36"
},
{
"name": "guzzlehttp/streams",
"version": "1.4.0",
"source": {
"type": "git",
"url": "https://github.com/guzzle/streams.git",
"reference": "3b761a328e5ed6ed519e960aded95d7acbe77894"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/guzzle/streams/zipball/3b761a328e5ed6ed519e960aded95d7acbe77894",
"reference": "3b761a328e5ed6ed519e960aded95d7acbe77894",
"shasum": ""
},
"require": {
"php": ">=5.4.0"
},
"require-dev": {
"phpunit/phpunit": "~4.0"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.4.x-dev"
}
},
"autoload": {
"psr-4": {
"GuzzleHttp\\Stream\\": "src/"
},
"files": [
"src/functions.php"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Michael Dowling",
"email": "mtdowling@gmail.com",
"homepage": "https://github.com/mtdowling"
}
],
"description": "Provides a simple abstraction over streams of data (Guzzle 4+)",
"homepage": "http://guzzlephp.org/",
"keywords": [
"Guzzle",
"stream"
],
"time": "2014-07-19 18:43:42"
}
],
"packages-dev": [],
"aliases": [],
"minimum-stability": "stable",
"stability-flags": [],
"platform": [],
"platform-dev": []
}
EDIT 3
composer config -l output:
[repositories.packagist.type] composer
[repositories.packagist.url] https?://packagist.org
[repositories.packagist.allow_ssl_downgrade] true
[process-timeout] 300
[use-include-path] false
[preferred-install] auto
[notify-on-install] true
[github-protocols] [git, https]
[vendor-dir] vendor
[bin-dir] {$vendor-dir}/bin (vendor/bin)
[cache-dir] C:/Users/User/AppData/Local/Composer
[cache-files-dir] {$cache-dir}/files (C:/Users/User/AppData/Local/Composer/files)
[cache-repo-dir] {$cache-dir}/repo (C:/Users/User/AppData/Local/Composer/repo)
[cache-vcs-dir] {$cache-dir}/vcs (C:/Users/User/AppData/Local/Composer/vcs)
[cache-ttl] 15552000
[cache-files-ttl] 15552000
[cache-files-maxsize] 300MiB (314572800)
[discard-changes] false
[prepend-autoloader] true
[github-domains] [github.com]
[home] C:/Users/User/AppData/Roaming/Compose
Source: (StackOverflow)
Pretty new to PHP and I am stuck on a (what I consider) a strange issue. I have spliced this file together, (it was split across several different functions) for testing, and to make it easier to explain the issue.
This is a basic while loop in Laravel and it seems to be exiting prematurely but oddly not exiting out to the line AFTER the loop, but exiting out BEFORE the loop and then entering again. Can't for the life of me workout why. I have added some log events throughout the function so I could try understand what was happening.
This is correctly fetching and writting products to the DB up until page 7 and then I get a "Start API Helper" event on log but never get an "End API helper". So somewhere in page 7 something is causing the while loop to exit out to the lines above, reset the pagecount to 0. then re-enter the loop, fetching the first lot of products and throwing an SQL duplicate key exception when writing. I know it is exiting out to before the loop as I get a "Before while", right after "New Client" in the log. And of course, the pagecount is resetting. How can this happen?
Any help would be so greatly appreciated.
public function store()
{
$items = array();
Log::info('Before while');
$pagecount = 0;
$prodcount = 1;
while ($prodcount > 0) {
Log::info('Top of while');
$prodcount = 0; // Reset product counter
Log::info('Page Count:'.$pagecount);
Log::info('Start API Helper');
$headers = array(
'NETOAPI_KEY' => env('NETO_API_KEY'),
'Content-Type' => 'application/json',
'Accept' => 'application/json',
'NETOAPI_ACTION' => 'GetItem'
);
Log::info('Headers Declared');
$body = '{
"Filter": {
"DateAddedFrom" : "2013-06-01 12:00:00",
"Page": "'.$pagecount.'",
"Limit": "500",
"OutputSelector": [
**Lots of JSON here - removed for readability**
]
}
}';
Log::info('Start API Helper');
$client = new client();
Log::info('New Client');
try {
$res = $client->post(env('NETO_API_URL'), [ 'headers' => $headers , 'body' => $body ]);
} catch (RequestException $e) {
echo $e->getRequest();
Log::error($e->getRequest());
if ($e->hasResponse()) {
echo $e->getResponse();
Log::error($e->getResponse());
}
}
Log::info('End API Helper');
$items = json_decode(utf8_encode($res->getBody()), true);
foreach($items["Item"] as $item)
{
// JSON is returning an empty array for empty strings. Need to convert to empty string for SQL save.
foreach($item as $key => $value){
if (empty($value)) {
$item["$key"] = "";
}
}
$Product = new Item;
$Product->SKU = array_get($item, 'SKU');
** LOTS OF DB FIELDS REMOVED FROM HERE FOR READABILITY**
$Product->save();
$prodcount++;
}
$pagecount++;
Log::info($prodcount.' products written to DB:');
Log::info('Bottom of while');
};
Log::info('Exited While');
return 'Complete';
}
UPDATE: I have modified the ELoquent SQL Client to a firstorNew to avoid any potential Duplicate key errors. Now the logs show the same 'while exit' at page 7 (occasionally page 8) which then re-enters the loop at page 0 BUT the weirdest thing is that it seems to end up with 2 instances of the loop running. Then eventually 3 instances, then 4. Then it throws a memory exhausted exception. The logs looks like.
local.INFO: Page Count:1
local.INFO: Page Count:2
local.INFO: Page Count:3
local.INFO: Page Count:4
local.INFO: Page Count:5
local.INFO: Page Count:6
local.INFO: Page Count:7
local.INFO: Page Count:8
local.INFO: Page Count:0
local.INFO: Page Count:9
local.INFO: Page Count:1
local.INFO: Page Count:10
local.INFO: Page Count:2
local.INFO: Page Count:11
local.INFO: Page Count:3
local.INFO: Page Count:12
...And so on...
Is it possible that a malformed JSON API response could be causing this? Perhaps I'll try limit the paging to 25 or so, so I can access the response causing the loop break?
Source: (StackOverflow)
I am trying to upload picture using TelegramBot API using the following code
if(file_exists($_FILES['fileToUpload']['tmp_name'])){
$new = fopen($_FILES['fileToUpload']['tmp_name'], "rb");
$contents = fread($new, $_FILES['fileToUpload']['size']);
fclose($new);
$client = new Client();
$response = $client->post("https://api.telegram.org/botMyApiKey/sendPhoto", [
'body' => ['chat_id' => '11111111', 'photo' => $contents]
]);
var_dump($response);
}else{
echo("No File");
}
I am getting Nginx 502 Bad Gateway
. Am I using the correct method? I have no issues in obtaining getMe using the API.
P.S I am using Guzzle 5.3.0 for php compatibility.
Source: (StackOverflow)
I've been searching for about 2 hours and I can't figure it out how to read the final response uri.
In previous versions of PHP Guzzle you just call $response->getEffectiveUrl()
and you get it.
I expected to have something similar in the new version so the final code looks like this:
$response = $httpClient->post('http://service.com/login', [
'form_params' => [
'user' => $user,
'padss' => $pass,
]
]);
$url = $response->getEffectiveUrl();
But in the latest version $response
is now a GuzzleHttp\Psr7\Response
and there is no method which allow me to retrieve the uri.
I read about the redirects here (http://guzzle.readthedocs.org/en/latest/quickstart.html#redirects) but it says nothing about
Source: (StackOverflow)
I'm trying to build an endpoint that forwards the data passed to it to an API using the Slim PHP Framework and I'm having trouble getting my response from a Guzzle request.
$app->map( '/api_call/:method', function( $method ) use( $app ){
$client = new GuzzleHttp\Client([
'base_url' => $app->config( 'api_base_url' ),
'defaults' => [
'query' => [ 'access_token' => 'penises' ],
]
]);
$request = $client->createRequest( $app->request->getMethod(), $method, [
'query' => $app->request->params()
]);
var_dump( $client->send( $request )->getBody() );
})->via( 'GET', 'POST', 'PUT', 'PATCH', 'DELETE' )->conditions( [ 'route' => '.+?' ] );`
This then gives me...
object(GuzzleHttp\Stream\Stream)[59]
private 'stream' => resource(72, stream)
private 'size' => null
private 'seekable' => boolean true
private 'readable' => boolean true
private 'writable' => boolean true
private 'meta' =>
array (size=6)
'wrapper_type' => string 'PHP' (length=3)
'stream_type' => string 'TEMP' (length=4)
'mode' => string 'w+b' (length=3)
'unread_bytes' => int 0
'seekable' => boolean true
'uri' => string 'php://temp' (length=10)
...instead of the response of 'cool' I was expecting.
If I just var_dump $client->sendRequest( $request )
I get a 200 OK, and the url is what I expect, http://localhost:8000/test?access_token=penises
.
I have another request, but only using $client->post(...)
and it works fine without giving me the stream thing back.
I've tried reading the stream using the example at the bottom (http://guzzle.readthedocs.org/en/latest/http-client/response.html) but it's telling me feof
doesn't exist.
Anyone have any idea what I'm missing or doing wrong here?
Source: (StackOverflow)
I have a method that checks if a user has valid Session info. This is supposed to throw an Exception, Guzzle\Http\Exception\BadResponseException
but when I try to catch it :
catch (Guzzle\Http\Exception\BadResponseException $e)
{
return false;
}
return true
Laravel doesn't get to this code and immediately starts it's own error handling. And ideas on how to bypass Laravels own implementation and use my own Catch.
EDIT: I just found out Laravel uses the same Exception handler as Symfony, so I also added the Symfony2 tag.
EDIT 2:
I sort of fixed the issue by disabling Guzzle exceptions and checking the return header manually. It's a bit of a short cut but in this case, it does the job. Thanks for the responses!
Source: (StackOverflow)
Trying to use the YouTube API v3 to get some video(s) information, using Guzzle in Symfony2 using Service Descriptors.
When I run the script, I get this:
[curl] 60: SSL certificate problem: unable to get local issuer
certificate [url]
https://www.googleapis.com/youtube/v3/videos?id=2xbVbCoHBgA&part=snippet&key={MY_KEY}
500 Internal Server Error - CurlException
My descriptor looks like this:
{
"name": "YouTube",
"baseUrl": "https://www.googleapis.com",
"apiVersion": "v3",
"description": "YouTube GData Graph API",
"operations": {
"GetVideos": {
"httpMethod": "GET",
"uri": "/youtube/v3/videos",
"parameters": {
"id": {
"type":"string",
"location":"query",
"required": true
},
"part": {
"location": "query",
"default": "snippet"
},
"key": {
"location": "query",
"default": "{MY KEY}",
"static": true
},
"maxResults": {
"location": "query",
"default": 50
}
}
}
}
}
This is running on a local Ubuntu 14.04 development environment with a very basic LAMP stack going on.
Any ideas as to what might be causing this?
Source: (StackOverflow)
When doing a POST request with 2 parameters:
return $this->perform($client->post("/authenticate",null, array(
"username" => 'radupass',
"password" => '@alcool', //starting with an @
)));
where $client:
/**
* @return \Guzzle\Service\Client
*/
public function getClient()
{
if ($this->_client === null) {
$this->_client = new Guzzle\Service\Client($this->baseUrl, $this->_options);
$this->_client->setDefaultHeaders(array(
"X-WebsiteId" => $this->websiteId,
"X-AccessToken" => $this->accessToken,
));
}
return $this->_client;
}
I get the following exception:
2013/05/29 11:08:29 [error] [exception.Guzzle\Common\Exception\InvalidArgumentException] exception 'Guzzle\Common\Exception\InvalidArgumentException' with message 'Unable to open lcool for reading' in /home/xxx/site/vendor/guzzle/guzzle/src/Guzzle/Http/Message/PostFile.php:58
Stack trace:
#0 /home/xxx/site/vendor/guzzle/guzzle/src/Guzzle/Http/Message/PostFile.php(25): Guzzle\Http\Message\PostFile->setFilename('@lcool')
#1 /home/xxx/site/vendor/guzzle/guzzle/src/Guzzle/Http/Message/EntityEnclosingRequest.php(245): Guzzle\Http\Message\PostFile->__construct('password', '@lcool', NULL)
#2 /home/xxx/site/vendor/guzzle/guzzle/src/Guzzle/Http/Message/EntityEnclosingRequest.php(273): Guzzle\Http\Message\EntityEnclosingRequest->addPostFile('password', '@lcool', NULL, false)
#3 /home/xxx/site/vendor/guzzle/guzzle/src/Guzzle/Http/Message/RequestFactory.php(127): Guzzle\Http\Message\EntityEnclosingRequest->addPostFiles(Array)
#4 /home/xxx/site/vendor/guzzle/guzzle/src/Guzzle/Http/Client.php(256): Guzzle\Http\Message\RequestFactory->create('POST', 'http://api.subs...', Object(Guzzle\Common\Collection), Array)
#5 /home/xxx/site/vendor/guzzle/guzzle/src/Guzzle/Http/Client.php(336): Guzzle\Http\Client->createRequest('POST', '/authenticate', NULL, Array)
#6 /home/xxx/site/frontend/components/SubServerClient.php(117): Guzzle\Http\Client->post('/authenticate', NULL, Array)
Seems that the client is trying to open a file instead.
EDIT
Looking at the Guzzle source code I see in:
https://github.com/guzzle/guzzle/blob/master/src/Guzzle/Http/Message/RequestFactory.php#L88
if (is_array($body) || $body instanceof Collection) {
// Normalize PHP style cURL uploads with a leading '@' symbol
foreach ($body as $key => $value) {
if (is_string($value) && substr($value, 0, 1) == '@') {
$request->addPostFile($key, $value);
unset($body[$key]);
}
}
// Add the fields if they are still present and not all files
$request->addPostFields($body);
}
What if I want to escape that character?
Source: (StackOverflow)
I am writing a unit test for an API that I am developing. The API is written in the Codeigniter framework, that calls another API using Guzzle. The test I am writing verifies that the API call returns the correct response.
The Test.php file contains the following code
require '/application/libraries/apiWrappers/Breathehr.php';
class BreathehrTest extends PHPUnit_Framework_TestCase {
public function testCanReturnEmployeeArray() {
$breatheHR = new Breathehr();
$employees = $breatheHR->list_employees(1);
$this->assertArrayHasKey('employees', $employees);
}
}
The method that is being tested is as follows
class Breathehr {
function __construct() {
}
public function list_employees($page)
{
$client = new GuzzleHttp\Client(
['base_uri' => 'https://xxx/',
'headers' => ['X-API-KEY' => 'xxx'],
'verify' => false]
);
$request = $client->get('employees?page='.$page);
$employees = json_decode($request->getBody(true));
$employeeData = array(
'employees' => array(),
'pagination' => array()
);
$i = 0;
foreach($employees->employees as $employee) {
if($employee->status !== 'Ex-employee') {
$employeeData['employees'][$i]['firstName'] = $employee->first_name;
$employeeData['employees'][$i]['lastName'] = $employee->last_name;
$employeeData['employees'][$i]['jobTitle'] = $employee->job_title;
if(isset($employee->line_manager)) {
$employeeData['employees'][$i]['lineManagerName'] = $employee->line_manager->first_name . ' '. $employee->line_manager->last_name;
$employeeData['employees'][$i]['lineManagerID'] = $employee->line_manager->id;
}
$employeeData['employees'][$i]['workingHours'] = $employee->full_or_part_time;
$employeeData['employees'][$i]['email'] = $employee->email;
$employeeData['employees'][$i]['workPhone'] = $employee->ddi;
$employeeData['employees'][$i]['personalMobile'] = $employee->personal_mobile;
$employeeData['employees'][$i]['homeTelephone'] = $employee->home_telephone;
$employeeData['employees'][$i]['birthday'] = $employee->dob;
$i++;
}
}
$nextLink = $request->getHeader('Link');
$nextLinkSplit = explode(',', $nextLink[0]);
$pageination = array();
foreach($nextLinkSplit as $data) {
$split = explode(';', $data);
preg_match('/"(.*?)"/', $split[1], $keyMatch);
$key = isset($keyMatch[1]) ? $keyMatch[1] : FALSE;
$number = substr($split[0], -2, 1);
$pageination[$key] = $number;
}
array_push($employeeData['pagination'], $pageination);
return $employeeData;
}
}
The API call works correctly via Postman and from a browser, but the result of running PHPUnit from the command line is the following
RuntimeException: Error creating resource: [message] fopen(): Unable
to find the wrapper "https" - did you forget to enable it when you
configured PHP?
[message] fopen(https://api.breathehr.com/v1/employees?page=1): failed
to open stream: No such file or directory
I have googled the error message and came across this SO post Unable to find the wrapper "https" - did you forget to enable it when you configured PHP?
Making these changes has made no difference. It's worth noting this is on localhost, running MAMP.
Any ideas?
Thanks
Source: (StackOverflow)
I'm trying to write a wrapper around an api my company is developing. It's restful, and using Postman I can send a post request to an endpoint like http://subdomain.dev.myapi.com/api/v1/auth/
with a username and password as POST data and I am given back a token. All works as expected. Now, when I try and do the same from PHP I get back a GuzzleHttp\Psr7\Response
object, but can't seem to find the token anywhere inside it as I did with the Postman request.
The relevant code looks like:
$client = new Client(['base_uri' => 'http://companysub.dev.myapi.com/']);
$response = $client->post('api/v1/auth/', [
'form_params' => [
'username' => $user,
'password' => $password
]
]);
var_dump($response); //or $resonse->getBody(), etc...
The output of the code above looks something like (warning, incoming wall of text):
object(guzzlehttp\psr7\response)#36 (6) {
["reasonphrase":"guzzlehttp\psr7\response":private]=>
string(2) "ok"
["statuscode":"guzzlehttp\psr7\response":private]=>
int(200)
["headers":"guzzlehttp\psr7\response":private]=>
array(9) {
["connection"]=>
array(1) {
[0]=>
string(10) "keep-alive"
}
["server"]=>
array(1) {
[0]=>
string(15) "gunicorn/19.3.0"
}
["date"]=>
array(1) {
[0]=>
string(29) "sat, 30 may 2015 17:22:41 gmt"
}
["transfer-encoding"]=>
array(1) {
[0]=>
string(7) "chunked"
}
["content-type"]=>
array(1) {
[0]=>
string(16) "application/json"
}
["allow"]=>
array(1) {
[0]=>
string(13) "post, options"
}
["x-frame-options"]=>
array(1) {
[0]=>
string(10) "sameorigin"
}
["vary"]=>
array(1) {
[0]=>
string(12) "cookie, host"
}
["via"]=>
array(1) {
[0]=>
string(9) "1.1 vegur"
}
}
["headerlines":"guzzlehttp\psr7\response":private]=>
array(9) {
["connection"]=>
array(1) {
[0]=>
string(10) "keep-alive"
}
["server"]=>
array(1) {
[0]=>
string(15) "gunicorn/19.3.0"
}
["date"]=>
array(1) {
[0]=>
string(29) "sat, 30 may 2015 17:22:41 gmt"
}
["transfer-encoding"]=>
array(1) {
[0]=>
string(7) "chunked"
}
["content-type"]=>
array(1) {
[0]=>
string(16) "application/json"
}
["allow"]=>
array(1) {
[0]=>
string(13) "post, options"
}
["x-frame-options"]=>
array(1) {
[0]=>
string(10) "sameorigin"
}
["vary"]=>
array(1) {
[0]=>
string(12) "cookie, host"
}
["via"]=>
array(1) {
[0]=>
string(9) "1.1 vegur"
}
}
["protocol":"guzzlehttp\psr7\response":private]=>
string(3) "1.1"
["stream":"guzzlehttp\psr7\response":private]=>
object(guzzlehttp\psr7\stream)#27 (7) {
["stream":"guzzlehttp\psr7\stream":private]=>
resource(40) of type (stream)
["size":"guzzlehttp\psr7\stream":private]=>
null
["seekable":"guzzlehttp\psr7\stream":private]=>
bool(true)
["readable":"guzzlehttp\psr7\stream":private]=>
bool(true)
["writable":"guzzlehttp\psr7\stream":private]=>
bool(true)
["uri":"guzzlehttp\psr7\stream":private]=>
string(10) "php://temp"
["custommetadata":"guzzlehttp\psr7\stream":private]=>
array(0) {
}
}
}
The output from Postman was something like:
{
"data" : {
"token" "fasdfasf-asfasdfasdf-sfasfasf"
}
}
Clearly I'm missing something about working with the response objects in Guzzle. The Guzzle response indicates a 200 status code on the request, so I'm not sure exactly what I need to do to retrieve the returned data.
Source: (StackOverflow)
Guzzle throws an exception if an error occured during the request. Unfortunately, there does not seem to be an error specific to timeouts - which is important for me as I know that those can ocassionally occur. I'd like to retry the corresponding request and need to able to tell if the error occured due to a timeout.
From the docs:
// Timeout if a server does not return a response in 3.14 seconds.
$client->get('/delay/5', ['timeout' => 3.14]);
// PHP Fatal error: Uncaught exception 'GuzzleHttp\Exception\RequestException'
The RequestException
has the info in itsmessage
property:
"cURL error 28: Operation timed out after 3114 milliseconds with 0 bytes received"
So I could evaluate the message pattern but this feels kinda wrong, because those messages could easily be changed in the future.
Is there a better/more stable way to check for timeouts when using guzzle 4?
Source: (StackOverflow)