So i have found on the Api from Amazon that you can start and stop the instance with this
$result = $client->startInstances([/* ... */]);
and also like this
$promise = $client->startInstances([/* ... */]);
So here is my question. Are there any diffrences between the $promise and the $result.
From the PHP SDK for EC2 documentation page that you linked in your Question:
Each of the following operations can be created from a client using $client->getCommand('CommandName'), where "CommandName" is the name of one of the following operations. Note: a command is a value that encapsulates an operation and the parameters used to create an HTTP request.
You can also create and send a command immediately using the magic methods available on a client object: $client->commandName(/* parameters */). You can send the command asynchronously (returning a promise) by appending the word "Async" to the operation name: $client->commandNameAsync(/* parameters */).
Related
I want to call roadrunners RPC method log from PHP.
I have an instance of Spriral\Goridge\RPC in $rpc and it is connected to the running roadrunner rpc via TCP. On that RPC instance I execute the following call, where $payload is a normal string. also tried with php array or json string and tried different flags for the third argument (Relay::PAYLOAD_RAW, Relay::PAYLOAD_CONTROL etc.)
$rpc->call('log', $payload);
but I always get this error message:
Spiral\Goridge\Exceptions\ServiceException: error 'rpc: service/method request ill-formed: log' on 'tcp://127.0.0.1:6001' in /var/www/vendor/spiral/goridge/src/RPC.php:123
I cannot find any documentation about it, but the log RPC method is there, just need to know how to format the $payload and if required which $flags to add as thrid argument.
There are no log methods available in the RRv2 via RPC.
I'm using SolrClient with SolrQuery object, but I need to add RawQueryParameters to it:
How is this done? I'm fairly new to Solr requests and I could not find such option in the documentation.
So far I have this:
$SolrQuery = new \SolrQuery();
$SolrQuery->setStart($this->offset);
$SolrQuery->setRows($this->limit);
$SolrQuery->setQuery($request);
$SolrQuery->addField('*')->addField('units:[subquery]');
$SolrQuery->addParam('units.q', '{!terms%20f=id%20v=$row.unit_ids}');
When running toString() on this object, I get:
start=0&rows=2147483647&q=type:address&fl=*,units:[subquery]&units.q={!terms%20f=id%20v=$row.unit_ids}
what is the correct query. This works fine in CLI, but gives exception when executed in PHP as $queryResponse = $SolrClient->query($SolrQuery);:
Exception: while invoking units:[subquery] on doc=SolrDocument{id=stored,indexed,tokenized,omitNorms,indexOptions=DOCS
EDIT: Solution was to use addParam() without urlcoded request. Spaces go through just fine!
You can get the active parameters by calling ->toString() on the SolrQuery object - since SolrQuery inherits from SolrModifiableParams, you can call addParam directly on the query object to add custom parameters. This lets you add any parameter you want to the request. Be careful to add the parameter verbatim, since SolrQuery should handle necessary escaping for you.
If you still see an error, you can check the logging on the Solr server (under Admin -> Logging). If the log level is set to INFO, Solr will log all requests so you can see what Solr actually got. Any exceptions should also be present in this log if they're generated on the Solr side.
The Solr extension will usually throw exceptions as the class SolrClientException, which can be useful to determine the source of the error. A list of exception messages are also available in the extension source if you need to debug further.
I am currently busy with a PSR-7 project with responses and requests.
Currently we are setting up an application in our index.php by doing something like:
$app = new Application();
$app->loadConfiguration(
'../config/global.yml',
);
// Should return the response?
$app->run((new ServerRequestFactory())->createServerRequestFromGlobals());
Here the run method also calls an emit method that is responsible for sending the headers and printing the body of the response.
The request and respons are now linked together in one call which makes it hard to test since you don't want to send the response with the headers straight to PHPUnit.
I have removed the emit call in the chain of the run method and added this to the index after the run method call:
// Send the response.
$app->send();
This way they are decoupled but the downside is I now have to hold a instance of my response in a response property inside my Application.php($app) class.
I want to move the response instance to the response class itself but my co-workers thinks a class should never hold an instance of itself. Yet when I look at frameworks this happens quite a lot. Is he right about this?
What arguments can I make to decouple my request and response besides easier testing?
I am pretty new to unit testing, one of the arguments I have already heard is that I should not test the full application anyways but rather separate components and therefore should not be worried about de-coupling the request and response.
I'm trying to delete a resource using ZF1 rest client
$this->restClient = new Zend_Rest_Client('https://myurl.com');
$response = $this->restClient->delete('/service/'.$this->uuid.'.json?api_key='.$this->apikey);
but I get an error:
Path "/service/v-2149d050-c64b-0131-33b0-1231390c0c78.json?api_key=a-9a136a00-b340-0131-2662-1231390c0c78" is not a valid HTTP path
the web service documentation simply says to use
DELETE https://myurl.com/service/YOUR_UUID.json?api_key=YOUR_API_KEY
any idea on how to use this class?
thanks
DELETE https://myurl.com/service/YOUR_UUID.json?api_key=YOUR_API_KEY
That is not the path only, but a full URI. It breaks down to:
Path: service/YOUR_UUID.json
Query-Info: api_key=YOUR_API_KEY
For Zend rest client, you need to call one function per each parameter, and a parameter can not be named as a standard HTTP verb:
$client = new Zend_Rest_Client('https://exeample.com');
$client->api_key(YOUR_API_KEY);
$response = $client->restClient->delete('/service/'.$this->uuid.'.json);
For more information please see the Request Arguments section in the vendor documentation on how to pass arguments with your request.
I have a generic HTTP file access API which I use for the system I'm working on. To make it as flexible as possible, it returns request and response data in the form of HTTP strings.
I'm currently implementing a version which interacts with the S3, via the AWS SDK for PHP 2.
Is there an easy way to quickly get the Request and Response HTTP requests which the S3Client makes when performing operations? If not, is there a more piecemeal way which I can use to not have to fake it?
Basically, I'd like the full-text of both the Request and Response on demand, or at least access to relevant data (headers, response codes, URLs, etc) so I can properly populate the return data for my framework.
Thanks.
You can get either the request or response object from a command object. Assuming $s3 holds an instance of Aws\S3\S3Client, you could do something like this:
$command = $s3->getCommand('ListObjects', array('Bucket' => '<bucket-name>'));
$request = $command->getRequest();
$response = $command->getResponse();
Those objects have methods for viewing the body, headers, status codes, etc. and you can cast them to string to see the string form.
If you want to quickly see the request and response as you are executing commands, you can attach the wire logger, and see what comes out on STDOUT (or STDERR)
$s3->addSubscriber(\Guzzle\Plugin\Log\LogPlugin::getDebugPlugin());
$s3->listObjects(array('Bucket' => '<bucket-name>'));
You will need to look into the Guzzle\Http\Client class, which is an ancestor class to S3Client, to have a look at the methods that it makes available. You can always override some of these methods in your own child of S3Client to make accessing this information easier for you.
Ultimately the data you are looking for resides in an object of class Guzzle\Http\Message\Response, which I believe is returned from Guzzle\Http\Client::send().
So perhaps in your own implementation of S3Client you can override the send() method to send the HTTP requests, then process the response data as needed.