guzzle

upload images to web service with laravel

旧城冷巷雨未停 提交于 2019-12-08 11:13:01
问题 I'm using Laravel 5.4 and Guzzle to upload files and images to another server. I am using the following method on the client/server side public function store (Request $request) { $dataForm = $request->all(); $Client = new Client(); $response = $Client->post('http://localhost/WebService/public/api/client', [ 'multipart' => [ [ 'name' => 'UploadIMG', 'filename' => 'image_org', 'Mime-Type' => 'image_mime', 'contents' => $ request->file('UploadIMG'), ], ] ]); $ response = $ response-> getBody ()

Why my second call on url doesn't work (Laravel,Guzzle)?

∥☆過路亽.° 提交于 2019-12-08 09:23:28
问题 This is a function where i call 2 api, from first i get client_id which i used in second url. Problem is that after i call second url my page is loading without end. Page image public function getDevices(){ $route='http://localhost:8000/api/devices'; $device= new Client(); $answer= $device->request('GET', $route); $body = $answer->getBody(); $status = 'true'; $message = 'Data found!'; $final= json_decode($body); $id_array = array(); foreach ($finalas $item) { // Add each id value in your

Sending multiple goutte requests asynchronously

半腔热情 提交于 2019-12-08 08:52:21
问题 This is the code I am using require_once 'goutte.phar'; use Goutte\Client; $client = new Client(); for($i=0;$i<10;$i++){ $crawler = $client->request('GET', 'http://website.com'); echo '<p>'.$crawler->filterXpath('//meta[@property="og:description"]')->attr('content').'</p>'; echo '<p>'.$crawler->filter('title')->text().'</p>'; } This works but takes a lot of time to process? Is there any way to do it faster. 回答1: For starters, there is nothing asynchronous about your code sample. Which means

Stream remote file with PHP and Guzzle

倾然丶 夕夏残阳落幕 提交于 2019-12-08 07:56:23
问题 My application should stream back to the browser a large file, that is server remotely. Currently the file is served from a local NodeJS server. I am using a VirtualBox Disk image of 25GB, just to be sure that it is not stored in memory while streaming. This is the related code I'm struggling with require __DIR__ . '/vendor/autoload.php'; use GuzzleHttp\Stream\Stream; use GuzzleHttp\Stream\LimitStream; $client = new \GuzzleHttp\Client(); logger('==== START REQUEST ===='); $res = $client-

Changing parameter values of Guzzle commands at runtime, through plugins?

自古美人都是妖i 提交于 2019-12-08 07:33:01
问题 This is (part of) the definition of BaseOperation , with one mandatory parameter ( foo ): 'BaseOperation' => array( 'class' => 'My\Command\MyCustomCommand', 'httpMethod' => 'POST', 'parameters' => array( 'foo' => array( 'required' => true, 'location' => 'query' ) ) ) Inside ChangeMethodPlugin plugin I need to modify the value of foo at runtime: class ChangeMethodPlugin implements EventSubscriberInterface { public static function getSubscribedEvents() { return array('command.before_send' =>

Guzzle 5.3: Unable to POST JSON body if larger than ~1MB

血红的双手。 提交于 2019-12-08 06:42:32
问题 I'm using Guzzle 5.3 via Guzzle Services (via https://github.com/ticketevolution/ticketevolution-php) to attempt to POST to an API endpoint with a JSON body that includes a PDF encoded as base64. When the body is less than ~1MB it works fine. When the body is larger it seems that the body is never sent. I have tested this with and without the Expect: 100 header and it does not seem to make a difference. I have tested with Transfer-Encoding: chunked, but because the API needs the entire POST

File not closed on Request “Complete” using guzzle 5.3

前提是你 提交于 2019-12-08 06:23:59
问题 We are uploading 1500+ files using a guzzle pool. Since we don't want to run into "too many open files" we figured we could use the event "before" to do the fopen and the "complete" to fclose the stream. PHP is not effectively closing the resource (and we hit the too many open files). Any idea what is happening / What we can do to fix this issue? Here's the code: $client = new GuzzleHttp\Client(); $requests = []; foreach($files as $fileName) { $options = [ 'debug' => false, 'events' => [

How to use Guzzle on Codeigniter?

梦想的初衷 提交于 2019-12-07 20:38:33
问题 I am creating a web application on Codeigniter 3.2 which works with the Facebook Graph API. In order to make GET & POST HTTP requests, I need a curl library for Codeigniter. I have found Guzzle but I Don't know how to use Guzzle on Codeigniter. 回答1: Check this link: https://github.com/rohitbh09/codeigniter-guzzle $this->load->library('guzzle'); # guzzle client define $client = new GuzzleHttp\Client(); #This url define speific Target for guzzle $url = 'http://www.google.com'; #guzzle try { #

Guzzle pool in PHP application

南楼画角 提交于 2019-12-07 17:03:47
问题 I am trying to use Guzzle pool in PHP. But I am having difficulty in dealing with ASYNC request. Below is the code snippet. $client = new \GuzzleHttp\Client(); function test() { $client = new \GuzzleHttp\Client(); $request = $client->createRequest('GET', 'http://l/?n=0', ['future' => true]); $client->send($request)->then(function ($response) { //echo 'Got a response! ' . $response; return "\n".$response->getBody(); }); } $res = test(); var_dump($res); // echoes null - I know why it does so

How to check if endpoint is working when using GuzzleHTTP

爱⌒轻易说出口 提交于 2019-12-07 12:13:01
问题 So I am working with guzzleHttp and I can get the responses that I am after and catch errors. The only problem I am having is that if the base URI is wrong, the whole script fails... how can I do some sort of checking to make sure that the endpoint is actually up? $client = new GuzzleHttp\Client(['base_uri' => $url]); 回答1: You might have many issues with your query, not only that the endpoint is down. Network interface on your server can go down right at the moment of query, DNS can go down,