I am trying to download an external file using guzzle. This is the code that I use:
// $url is a URL I receive from Openload's API request
$url = 'https://abvzps.example.com/dl/l/4spxX_-cSO4/The+quick+brown+fox.mp4';
$path = storage_path('app/remote-uploads/test.mp4');
$client = new Client();
$client->get($url, ['sink' => $path]);
The code works and downloads from localhost just fine, but when I push it to production I receive this error:
[2017-03-25 19:08:06] production.ERROR: RuntimeException: Cannot read from non-readable stream in /var/www/vhosts/clooud.tv/httpdocs/vendor/guzzlehttp/psr7/src/Stream.php:208
Stack trace:
#0 /var/www/vhosts/clooud.tv/httpdocs/vendor/guzzlehttp/guzzle/src/Exception/RequestException.php(132): GuzzleHttp\Psr7\Stream->read(120)
#1 /var/www/vhosts/clooud.tv/httpdocs/vendor/guzzlehttp/guzzle/src/Exception/RequestException.php(105): GuzzleHttp\Exception\RequestException::getResponseBodySummary(Object(GuzzleHttp\Psr7\Response))
#2 /var/www/vhosts/clooud.tv/httpdocs/vendor/guzzlehttp/guzzle/src/Middleware.php(65): GuzzleHttp\Exception\RequestException::create(Object(GuzzleHttp\Psr7\Request), Object(GuzzleHttp\Psr7\Response))
#3 /var/www/vhosts/clooud.tv/httpdocs/vendor/guzzlehttp/promises/src/Promise.php(203): GuzzleHttp\Middleware::GuzzleHttp\{closure}(Object(GuzzleHttp\Psr7\Response))
#4 /var/www/vhosts/clooud.tv/httpdocs/vendor/guzzlehttp/promises/src/Promise.php(156): GuzzleHttp\Promise\Promise::callHandler(1, Object(GuzzleHttp\Psr7\Response), Array)
#5 /var/www/vhosts/clooud.tv/httpdocs/vendor/guzzlehttp/promises/src/TaskQueue.php(47): GuzzleHttp\Promise\Promise::GuzzleHttp\Promise\{closure}()
#6 /var/www/vhosts/clooud.tv/httpdocs/vendor/guzzlehttp/promises/src/Promise.php(246): GuzzleHttp\Promise\TaskQueue->run(true)
#7 /var/www/vhosts/clooud.tv/httpdocs/vendor/guzzlehttp/promises/src/Promise.php(223): GuzzleHttp\Promise\Promise->invokeWaitFn()
#8 /var/www/vhosts/clooud.tv/httpdocs/vendor/guzzlehttp/promises/src/Promise.php(267): GuzzleHttp\Promise\Promise->waitIfPending()
#9 /var/www/vhosts/clooud.tv/httpdocs/vendor/guzzlehttp/promises/src/Promise.php(225): GuzzleHttp\Promise\Promise->invokeWaitList()
#10 /var/www/vhosts/clooud.tv/httpdocs/vendor/guzzlehttp/promises/src/Promise.php(62): GuzzleHttp\Promise\Promise->waitIfPending()
#11 /var/www/vhosts/clooud.tv/httpdocs/vendor/guzzlehttp/guzzle/src/Client.php(129): GuzzleHttp\Promise\Promise->wait()
...
I am not quite sure how to go about this and would really appreciate any help!
It's hard to say something without the real URL and debugging.
Just set a breakpoint before the exception and take a look at the response. IMO it should contain an error, but I have no idea, which one exactly.
Related
I have a third party application which inserts product data to WooCommerce via the REST API. The third party application does not log outbound API requests.
The third party application is making a request to WooCommerce which is causing a PHP error.
[16-Jan-2023 14:52:23 UTC] PHP Fatal error: Uncaught TypeError: preg_match(): Argument #2 ($subject) must be of type string, WP_REST_Request given in /home/CENSORED/public_html/wp-includes/formatting.php:1596
Stack trace:
#0 /home/CENSORED/public_html/wp-includes/formatting.php(1596): preg_match('/[\\x80-\\xff]/', Object(WP_REST_Request))
#1 /home/CENSORED/public_html/wp-includes/formatting.php(2207): remove_accents(Object(WP_REST_Request))
#2 /home/CENSORED/public_html/wp-includes/class-wp-hook.php(310): sanitize_title(Object(WP_REST_Request))
#3 /home/CENSORED/public_html/wp-includes/plugin.php(205): WP_Hook->apply_filters(Object(WP_REST_Request), Array)
#4 /home/CENSORED/public_html/wp-includes/taxonomy.php(1751): apply_filters('pre_term_slug', Object(WP_REST_Request), 'pa_colour')
#5 /home/CENSORED/public_html/wp-includes/taxonomy.php(1653): sanitize_term_field('slug', Object(WP_REST_Request), 0, 'pa_colour', 'db')
#6 /home/CENSORED/public_html/wp-includes/taxonomy.php(2385): sanitize_term(Array, 'pa_colour', 'db')
#7 /home/CENSORED/public_html/wp-content/plugins/woocommerce/includes/rest-api/Controllers/Version3/class-wc-rest-terms-controller.php(407): wp_insert_term('DENIM BLUE', 'pa_colour', Array)
#8 /home/CENSORED/public_html/wp-includes/rest-api/class-wp-rest-server.php(1171): WC_REST_Terms_Controller->create_item(Object(WP_REST_Request))
#9 /home/CENSORED/public_html/wp-includes/rest-api/class-wp-rest-server.php(1018): WP_REST_Server->respond_to_request(Object(WP_REST_Request), '/wc/v2/products...', Array, NULL)
#10 /home/CENSORED/public_html/wp-includes/rest-api/class-wp-rest-server.php(442): WP_REST_Server->dispatch(Object(WP_REST_Request))
#11 /home/CENSORED/public_html/wp-includes/rest-api.php(410): WP_REST_Server->serve_request('/wc/v2/products...')
#12 /home/CENSORED/public_html/wp-includes/class-wp-hook.php(308): rest_api_loaded(Object(WP))
#13 /home/CENSORED/public_html/wp-includes/class-wp-hook.php(332): WP_Hook->apply_filters(NULL, Array)
#14 /home/CENSORED/public_html/wp-includes/plugin.php(565): WP_Hook->do_action(Array)
#15 /home/CENSORED/public_html/wp-includes/class-wp.php(399): do_action_ref_array('parse_request', Array)
#16 /home/CENSORED/public_html/wp-includes/class-wp.php(780): WP->parse_request('')
#17 /home/CENSORED/public_html/wp-includes/functions.php(1332): WP->main('')
#18 /home/CENSORED/public_html/wp-blog-header.php(16): wp()
#19 /home/CENSORED/public_html/index.php(17): require('/home/CENSORED...')
#20 {main}
thrown in /home/CENSORED/public_html/wp-includes/formatting.php on line 1596
I believe the PHP error is a bug that needs to be reported to WooCommerce and/or WordPress. I am unable to capture the contents of the request so that I can provide steps to reproduce for the bug report.
I am testing on a completely blank and up-to-date installation of WordPress and WooCommerce with no other plugins (except those mentioned below).
I have tried:
Looking in the Apache access log, the request body is not included
Using this plugin https://wordpress.org/plugins/wp-rest-api-log/ but it does not capture the request. It captures valid requests, but not the request that causes the error
Using this plugin https://wordpress.org/plugins/log-http-requests/ it does not appear to capture REST API requests
Using this code https://iandunn.name/2016/02/05/logging-wordpress-rest-api-errors/ it does not add any content to the error_log when the error occurs. I fired other invalid requests to the REST API and it did work, so I can only assume that the request is a valid REST API request syntactically and the resulting error is an internal PHP bug.
How can I capture the full request so that I can confirm this is a WooCommerce or WordPress bug and report to the appropriate github?
I suggest: "debugging by printf" or "debugging by print_r" in this special case.
Edit /home/CENSORED/public_html/index.php and insert just before line 17:
syslog(LOG_ERROR, print_r($_GET, TRUE));
syslog(LOG_ERROR, print_r($_POST, TRUE));
depending on the request type your plugin fires, the content should appear in one of these log outputs.
You could also go to /home/CENSORED/public_html/wp-includes/formatting.php and insert before line 1596:
syslog(LOG_ERROR, print_r($text, TRUE));
to get the malformed string variable.
After doing so, you should be able to find the log lines in the server's syslog via:
tail -f /var/log/syslog
If you unfortunately don't have access to the wp source code on the server machine, you should capture the request on the desktop machine which is running the plugin via Wireshark or TShark. I wouldn't blame it overkill. By filtering the capture by server IP, protocol http and method (http.request.method == GET or http.request.method == POST) the heart of the matter should be revealed soon (Maybe you have to reset the request scheme from https to http).
I am getting the error "Cannot modify header information - headers already sent" from PHP code.
Note that I am NOT getting the error "Cannot modify header information - headers already sent by (output started at [filename]:[linenumber])".
I get the former with SAPI=apache2module and the later with SAPI=cli.
I am quite familiar with the error, and can usually tell exactly where it is coming from. In my current case, I can't. (My best guess so far is that the mail() function is doing output.)
How do I convince PHP to use the form with "by (output started at %s:%d)"?
Examining PHP source, it apparently only uses the later form if the location was recorded. But what makes it record or not?
<?php
function exception_error_handler($errno, $errstr, $errfile, $errline ) {
throw new ErrorException($errstr, 0, $errno, $errfile, $errline);
}
set_error_handler("exception_error_handler");
try {
header('Content-Type: text/plain');
printf("before sapi = %s\n", php_sapi_name());
flush();
header('X-test: something');
print "after\n";
} catch (Exception $ex) {
print($ex);
}
Expected and correct, CLI:
$ php flush_test5.php
before sapi = cli
exception 'ErrorException' with message 'Cannot modify header information - headers already sent by (output started at /dir/file.php:10)' in /dir/file.php:12
Stack trace:
#0 [internal function]: exception_error_handler(2, 'Cannot modify h...', '/name/david/bar...', 12, Array)
#1 /dir/file.php(12): header('X-test: somethi...')
$
Obtained, apache2module:
before sapi = apache2handler
exception 'ErrorException' with message 'Cannot modify header information - headers already sent' in /dir/file.php:12
Stack trace:
#0 [internal function]: exception_error_handler(2, 'Cannot modify h...', '/name/david/bar...', 12, Array)
#1 /dir/file.php(12): header('X-test: somethi...')
#2 {main}
I would like to get, from apache2module:
before sapi = apache2handler
exception 'ErrorException' with message 'Cannot modify header information - headers already sent by (output started at /dir/file.php:10)' in /dir/file.php:12
Stack trace:
#0 [internal function]: exception_error_handler(2, 'Cannot modify h...', '/name/david/bar...', 12, Array)
#1 /dir/file.php(12): header('X-test: somethi...')
#2 {main}
My website is on windows azure web-app. I am using below SOAP message.
$soap_client = new SoapClient("http://ip_address/service.asmx?WSDL", array("trace" => true));
$params = new \SoapVar('<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<Beneficiary_Address1 xmlns="" />
<Beneficiary_Address2 xmlns="" />
<Beneficiary_Address3 xmlns="" />
<Beneficiary_ZIP_Code xsi:nil="true" xmlns="" />
<Beneficiary_EmailID xsi:nil="true" xmlns="" />
<Beneficiary_Contact_No xmlns="" />
</soap:Body>
</soap:Envelope>', XSD_ANYXML);
try{
$response = $soap_client->__soapCall('RemittanceService', array($params));
highlight_string($soap_client->__getLastRequest());
}
catch(SoapFault $fault){
die("SOAP Fault: fault code: {$fault->faultcode}, fault string: {$fault->faultstring}");
}
And it's giving me this fault message:
fault code: HTTP, fault string: Bad Request
I don't know what does it mean? Let me know if you need more information.
Thanks.
Stack Trace
SoapFault exception: [HTTP] Bad Request in /var/www/mtes/public_html/application/controllers/bank_api_pnb.php:146
Stack trace:
#0 [internal function]: SoapClient->__doRequest('<?xml version="...', 'http://124.124....', 'http://tempuri....', 1, 0)
#1 /var/www/mtes/public_html/application/controllers/bank_api_pnb.php(146): SoapClient->__soapCall('RemittanceServi...', Array)
#2 [internal function]: Bank_api_pnb->test()
#3 /var/www/mtes/public_html/system/core/CodeIgniter.php(359): call_user_func_array(Array, Array)
#4 /var/www/mtes/public_html/index.php(220): require_once('/var/www/mtes/p...')
#5 {main}
The path '/var/www/mtes/...' is not valid, it is the web root on Linux. Web root on Azure Apps is wwwroot, when you migrate to Azure Apps, you may need to change configuration, and application settings to point to correct web root. If you have hard coded paths, you need to change them in code as well.
SoapFault is a PHP class, http://php.net/manual/en/soapfault.soapfault.php, the object $fault must have $faultcode and $faultstring when created,
$faultactor, $detail , $faultname, and $headerfault are optional, default to empty.
What you see from exception,
$faultcode is "soap:Server",
$faultstring is "An exception is thrown by the Orchestration schedule".
For debugging, you can add var_dump($fault) in catch statement, it could provide you more info, such as $faultactor, $detail , $faultname, and $headerfault.
I am using codeigniter to upload images to a amazon storage bucket.Iam getting this error and i dont know what to do to overcome this problem
Fatal error: Uncaught exception 'Guzzle\Http\Exception\CurlException' with message '[curl] 65: necessary data rewind wasn't possible [url] https://public-ww-lk.s3.amazonaws.com/images/gallery/the-kingsbury-colombo-sri-lanka-21401-293x154.jpg' in E:\projects\wwlk\application\third_party\Awsmy\vendor\guzzle\guzzle\src\Guzzle\Http\Curl\CurlMulti.php:338 Stack trace: #0 E:\projects\wwlk\application\third_party\Awsmy\vendor\guzzle\guzzle\src\Guzzle\Http\Curl\CurlMulti.php(279): Guzzle\Http\Curl\CurlMulti->isCurlException(Object(Guzzle\Http\Message\EntityEnclosingRequest), Object(Guzzle\Http\Curl\CurlHandle), Array) #1 E:\projects\wwlk\application\third_party\Awsmy\vendor\guzzle\guzzle\src\Guzzle\Http\Curl\CurlMulti.php(244): Guzzle\Http\Curl\CurlMulti->processResponse(Object(Guzzle\Http\Message\EntityEnclosingRequest), Object(Guzzle\Http\Curl\CurlHandle), Array) #2 E:\projects\wwlk\application\third_party\Awsmy\vendor\guzzle\guzzle\src\Guzzle\Http\Curl\CurlMulti.php(227): Guzzle\Http\Curl\CurlMulti->processMessages() #3 E:\pro in E:\projects\wwlk\application\third_party\Awsmy\vendor\aws\aws-sdk-php\src\Aws\Common\Client\AbstractClient.php on line 285
Try setting CURL option body_as_string to true.
Something like this:
<?php
$client->getConfig()->set('curl.options', array('body_as_string' => true));
I'm need a little help about WS SOAP Client in PHP.
I have a WS SOAP, restrict to my IP, but I don know almost anything about SOAP, I've already use SOAP with rails a long time ago.
If I access the SOAP server from my browser using this: http://thedomain.com/wssitedsv/site.asmx/RetornaGanhadores
The server return me the correct XML.
If I access the SOAP server from my browser using this:
http://thedomain.com/wssitedsv/site.asmx?wsdl
The server return a xml with configuration of the SOAP
In the PHP I'm doing it:
$url = "http://thedomain.com/wssitedsv/site.asmx?wsdl";
$client = new SoapClient($url);
$return = $client->RetornaGanhadores(NULL);
echo $return;
And I'm getting this error:
PHP Fatal error: Uncaught SoapFault exception: [HTTP] Could not connect to host in /Users/sidnei/Sites/suasorte/scripts/get_data.php:15
\\nStack trace:
\\n#0 [internal function]: SoapClient->__doRequest('<?xml version="...', 'http://192.168....', 'https://www.tte...', 1, 0)
\\n#1 /Users/sidnei/Sites/suasorte/scripts/get_data.php(15): SoapClient->__call('RetornaGanhador...', Array)
\\n#2 /Users/sidnei/Sites/suasorte/scripts/get_data.php(15): SoapClient->RetornaGanhadores(NULL)
\\n#3 /Users/sidnei/Sites/suasorte/index.php(2): include('/Users/sidnei/S...')
\\n#4 {main}
\\n thrown in /Users/sidnei/Sites/suasorte/scripts/get_data.php on line 15
I can get all methods from Server using this:
$url = "http://thedomain.com/wssitedsv/site.asmx?wsdl";
$client = new SoapClient($url);
$return = $client->__getFunctions();
print_t $return;
What I am doing wrong to use this SOAP server?
How use a SOAP Server in PHP?
I appreciate any help.
Thanks