I am migrating my application from php 5 to php 7.2.
I have a problem with theSoapclient call knowing that it works correctly with php 5.
After a lot of research I am progressing on my soapClient script with php 7.2, but I have a concern for stability.
The script will load the wsdl a few times, like 1 time out of 40 and then indicate a loading problem.
[message:protected] => SOAP-ERROR: Parsing WSDL: Couldn't load from 'http://ip?WSDL' : failed to load external entity "http://ip?WSDL"
I added the stream_context , cache_wsdl options but no stable result!
it worked twice with this code bellow
$option = array (
'location' => $optionSc['location'],
'uri' => $optionSc['location'],
'login' => $optionSc['login'],
'password' => $optionSc['password'],
'trace' => 1,
'connection_timeout' => 0,
'exceptions' => 1
);
after that it returns like I described first.
anyone can help me with that if he fixed this problem I did a lot of researches but nothing is working fine and I am relly blocked!
I've experienced a similar behaviour. PHP was reporting errors with parsing remote WSDL.
The problem was weak certificate used by the remote server that kept being refused by OpenSSL, even before being processed by PHP.
Problem
I have confirmed this by trying to download the WSDL using curl
curl REMOTE_ADDRESS
which reported the following error
error:14082174:SSL routines:SSL3_CHECK_CERT_AND_ALGORITHM:dh key too small.
The diffie-hellman key base was 1024 instead of recommended 2048 which I checked using openssl command (see https://weakdh.org/)
openssl s_client -showcerts -connect admonitoring.mediaresearch.cz:443 </dev/null
Solution
Until the certificate problem is fixed and a new one, more secure, issued, I have managed to fix this problem by temporarily lowering Openssl security settings.
In /etc/ssl/openssl.cnf (Debian) comment out the following line
# comment out the following line in /etc/ssl/openssl.cnf
CipherString = DEFAULT#SECLEVEL=2
# or set SECLEVEL to 1
CipherString = DEFAULT#SECLEVEL=1
Instead of changing the settings on the whole system, I solved it by using:
$options['ssl']['ciphers'] = 'DEFAULT#SECLEVEL=1';
in the stream_context
Related
A little background first: for some reason, making curl calls inside my Vagrant machine works only if I use --tlsv1.2 option, without that I get:
cURL error 35: SSL connect error (see http://curl.haxx.se/libcurl/c/libcurl-errors.html)
So I've put that value into configuration file, ~/.curlrc, so every time I run
curl https://myapi.com on the command line that option is used automatically, and it works fine.
However, I am currently playing with Guzzle 6, which uses curl to make API calls in the background. I assumed that curl that Guzzle uses will use the same configuration file ~/.curlrc, but seems not because I'm getting again: cURL error 35: SSL connect error.
This is the code that I'm using:
$client = new HttpClient(['defaults' => [
'verify' => false
]]);
$response = $client->request('GET', 'https://myapi.com', ['curl' => [
CURLOPT_SSLVERSION => 6,
]]);
As you can see, I even tried to pass TLSV1.2 value(value 6 is mapped to TLSV1.2 according to curl php documentation) to curl, but still nothing. Anybodu have an idea what could be wrong here?
EDIT: yeah, just confirmed that Guzzle uses some other curl binary. I moved the original one to another location and can't no longer accessed it from the command line, but after that Guzzle still returns the same error.
I am trying to connect to the google API from a localhost, but keep on receiving an exception (key changed - in text below).
Warning: file_get_contents(compress.zlib://https://www.googleapis.com/books/v1/volumes?q=Henry+David+Thoreau&filter=free-ebooks&key=bItatTTTTT7amAHYSaROTTTTTbtttuuuuuuuu) [function.file-get-contents]: failed to open stream: operation failed in C:\zendProject\zf2\vendor\google\apiclient\src\Google\IO\Stream.php on line 115
The code I am using in my browser comes straight from the API Guide and reads:
$client = new \Google_Client();
$client->setApplicationName("rent");
$service = new \Google_Service_Books($client);
$optParams = array('filter' => 'free-ebooks');
$results = $service->volumes->listVolumes('Henry David Thoreau', $optParams);
I think my problems relate to the config file, and that fact I am working off the localhost development server.
'Google_Auth_OAuth2' => array(
'application_name' => 'www.example.com',
'client_id' => '4498xxxxx061-3333xxxx9pjcpkbqhoxxxxxxxxxxx.apps.googleusercontent.com',
'client_secret' => '8xxxxxxxxx333xxxxxxxxx',
'redirect_uri' => 'http://localhost',
'developer_key' => 'AxxxxxxzBjpxxxxxaxxxxxxZxxx1xxxxx',
In the new developer console I have created a new client ID for the project and inserted the "Client_id", "Client_secret", etc.
I have also enabled the relevant APIs for Calenders and Books.
I have tested my API key on the URL I found for google fonts - so I am sure I have the right developer key.
I suspect the issue may be around the local host in uri fields, what do I need to put in here?
Does anyone know what I am doing wrong.
UPDATE: I found a post that suggested getting the HTTP response code here:
The response from the server is 304 - not sure if this helps
UPDATE: #Carlos Roubles - was correct I was using the incorrect version. Just in case anyone else runs into this issue - the composer information on the google website appears to be incorrect.
I previously used "google/apiclient": "1.0." this appears in the google documentation. I have now tried "google/apiclient": "1." and this seems to have fixed the problem.
Thats a problem with file_get_contents rather that with the api.
Most people changes file_get_contents to CURL for accesing remote files.
Anyways, i was checking the library and i cannot find any call to file_get_contents in all the stream.php file
https://github.com/google/google-api-php-client/blob/master/src/Google/IO/Stream.php
and in line 115, what we have is a commented line, so what comes to my mind is that yu are not using the last version of the library. Also, i see that in this version they make the request with fopen.
So you can try to update it, and probably this fixes the issue
I have a PHP script that pulls orders from ChannelAdvisor using the SoapClient and has worked perfect for the past year. I upgraded our Centos 6 server and now the script does not work. It looks like it may be an OpenSSL issue from what I have gathered on the Internet. I moved the script to a server that I haven't upgraded yet and it works like a champ. I have also noticed that I can no longer "wget" any HTTPS addresses without it erroring out.
$client = new SoapClient('https://api.channeladvisor.com/ChannelAdvisorAPI/v6/OrderService.asmx?WSDL', array('trace' => true, 'features' => SOAP_SINGLE_ELEMENT_ARRAYS, 'connection_timeout' => '2'));
This is error I am getting...
PHP Fatal error: SOAP-ERROR: Parsing WSDL: Couldn't load from 'https://api.channeladvisor.com/ChannelAdvisorAPI/v6/OrderService.asmx?WSDL' : failed to load external entity "https://api.channeladvisor.com/ChannelAdvisorAPI/v6/OrderService.asmx?WSDL" in get-orders-test.php on line 9
Any help is appreciated!
Here's the reduced but accurate code I'm working with.
$client = S3Client::factory(array('key'=>$ak,'secret'=>$sk));
foreach(range(1,10) as $i) $temp[] = array('Key'=>$i);
$result = $client->deleteObjects(array('Bucket'=>'bucket','Objects'=>$temp));
return $result;
Everything works, it deletes the objects as requested but it throws all of these errors from the phar file. Running this locally as you can see below.
Fatal error: Uncaught exception 'Guzzle\Http\Exception\CurlException' with message '[curl] 56: Problem (2) in the Chunked-Encoded data [url] https://bucket.s3.amazonaws.com?delete=' in phar://C:/wamp/www/bucket/local/aws.phar/Aws/Common/Client/AbstractClient.php on line 285
Guzzle\Http\Exception\CurlException: [curl] 56: Problem (2) in the Chunked-Encoded data [url] https://bucket.s3.amazonaws.com?delete= in phar://C:/wamp/www/bucket/local/aws.phar/Guzzle/Http/Curl/CurlMulti.php on line 365
Aws\Common\Exception\TransferException: [curl] 56: Problem (2) in the Chunked-Encoded data [url] https://bucket.s3.amazonaws.com?delete= in phar://C:/wamp/www/bucket/local/aws.phar/Aws/Common/Client/AbstractClient.php on line 285
I was also having this problem running WampServer on Windows 7 x64. Through dumb luck, I just stumbled across the solution.
Simply add 'scheme' => 'http' to the factory config settings and it starts working!
Little late I realize, but searches for this returned very little, hopefully this might help someone else.
I was also getting this error only when trying to deleteObjects, WAMPSERVER (64 BITS & PHP 5.4) 2.4, Windows 7 x64. I think something is wrong with the Curl extension in this version of WAMP. I installed WAMPSERVER (32BITS & PHP 5.4) 2.4 and had no issues with deleteObjects.
Possible solution is to add
'curl.options' => array('CURLOPT_HTTP_VERSION'=>'CURL_HTTP_VERSION_1_0')
to S3Client::factory options.
No more mentioned curl errors, but now I sometimes receive Simple XML error: "Entity: line 2: parser error : Extra content at the end of the document".
I am trying to get the content of WSDL from HTTPS Server
<?php
echo file_get_contents("https://zendsoap.lan/Zend_Soap_Server.php?wsdl");
?>
It Return:
Warning: file_get_contents() [function.file-get-contents]: SSL operation failed with code 1. OpenSSL Error messages: error:1408E0F4:SSL routines:func(142):reason(244) in /Applications/AMPPS/www/zendSoap.lan/Zend_Soap_Client.php on line 4
Warning: file_get_contents() [function.file-get-contents]: Failed to enable crypto in /Applications/AMPPS/www/zendSoap.lan/Zend_Soap_Client.php on line 4
Warning: file_get_contents(https://zendsoap.lan/Zend_Soap_Server.php?wsdl) [function.file-get-contents]: failed to open stream: operation failed in /Applications/AMPPS/www/zendSoap.lan/Zend_Soap_Client.php on line 4
AND when I can goto the WSDL Location (https://zendsoap.lan/Zend_Soap_Server.php?wsdl): Everything looks fine.
P.S: Can anybody tell me how can I share the WSDL file
I agree with RockyFord regarding it being an SSL issue (I'm pretty sure you will have a self signed certificate in place and due to using SSL there are a few steps you will need to take in order to minimise security concerns). Regarding the immediate issue you could try fixing it with code similar to this:
$url = 'https://zendsoap.lan/Zend_Soap_Server.php?wsdl';
$contextOptions = array(
'ssl' => array(
'verify_peer' => true,
'CN_match' => 'zendsoap.lan' // assuming zendsoap.lan is the CN used in the certificate
)
);
$sslContext = stream_context_create($contextOptions);
$wsdlContent = file_get_contents($url, NULL, $sslContext);
(UPDATE: It might seem like an easy solution to change the code above to
'verify_peer' => false
while it may be ok for basic development it's not really a good idea and definitely shouldn't be used in a production environment as it introduces serious security concerns - see this excellent article on How to properly secure remote API calls over SSL from PHP code by Artur Ejsmont for more on this subject as well as the Transport Layer Security Cheat Sheet and Securing Web Services by OWASP)
To pick up on your point regarding sharing a WSDL from within a Zend Framework application you could do something like this to get started:
// go to application/configs/application.ini
// if your APPLICATION_ENV is development then add the following line in the development section:
phpSettings.soap.wsdl_cache_enabled = 0
The line above will prevent your wsdl being cached during development. Next you might want to create a SoapController and add this action like this:
public function serverAction()
{
$baseUrl = 'http://zendsoap.lan/soap/server';
if( isset( $_GET['wdsl'] ) ) {
$strategy = new Zend_Soap_Wsdl_Strategy_AnyType();
$server = new Zend_Soap_AutoDiscover($strategy);
$server->setUri($baseUrl);
$server->setClass('Application_Model_Web_Service');
$server->handle();
} else {
$server = new Zend_Soap_Server($baseUrl . '?wsdl');
$server->setClass('Application_Model_Web_Service');
$server->handle();
}
}
The nice thing about the approach above is the WSDL will be generated for you on the fly. You will have noticed the setClass() method is going to be called with 'Application_Model_Web_Service' passed as the only parameter. To test your configuration I recommend you create that class and insert the method below. Testing your configuration with a simple service containing a single method will help you with troubleshooting before you make the service more complex. Here is the example method:
// Note: you should definitely comment your methods correctly in the class so
// the WSDL will be generated correctly - by that I mean use #param and #return
// so the correct input and output types can be determined and added to the WSDL
// when the the ZF component generates it for you
/**
* #return string
*/
public function getMessage()
{
return 'ok';
}
(UPDATE: Also in response to the question you asked regarding using Zend_Soap_Client to access the web service, since it looks like you're intending to make it a secure service I'd suggest you raise a separate question regarding setting up secure soap services with php. If you explain more about what you're trying to do in that question you may get some good input from a range of experts on best practices :-)
)
I know you're new to SO so if you're happy with the answer you can accept it, also generally it's best to just reply to an answer rather than add another answer to reply. Easy when you know how of course and even easier when someone tells you ;-)
I tried your way of defining The Soap Server, only thing was I used my custom class instead of using Application_Model_Web_Service. I am using single files for Client & Server. When I run https://zendsoap.lan/Zend_Soap_Server.php without ?wsdl it result in this:
<SOAP-ENV:Envelope>
<SOAP-ENV:Body>
<SOAP-ENV:Fault>
<faultcode>WSDL</faultcode>
<faultstring>SOAP-ERROR: Parsing WSDL: Couldn't load from 'https://zendsoap.lan/Zend_Soap_Server.php?wsdl' : failed to load external entity "https://zendsoap.lan/Zend_Soap_Server.php?wsdl"
</faultstring>
</SOAP-ENV:Fault>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
And When I try file_get_contents() the way you told, I get this:
Warning: file_get_contents() [function.file-get-contents]: SSL operation failed with code 1. OpenSSL Error messages: error:14090086:SSL routines:func(144):reason(134) in /Applications/AMPPS/www/zendSoap.lan/https_soap_test.php on line 16
Warning: file_get_contents() [function.file-get-contents]: Failed to enable crypto in /Applications/AMPPS/www/zendSoap.lan/https_soap_test.php on line 16
Warning: file_get_contents(https://zendsoap.lan/Zend_Soap_Server.php?wsdl) [function.file-get-contents]: failed to open stream: operation failed in /Applications/AMPPS/www/zendSoap.lan/https_soap_test.php on line 16
Here is link to screenshot of My Certificate:
http://i.stack.imgur.com/bKoVD.png
Loads of thanks for your help.
Problem solved By changing 'verify_peer' => false
Can you (#dkcwd) please tell me what should be the code if I use Zend_Soap_Client without file_get_contents(). I mean is there any option which i can't find on internet to do something similar to 'verify_peer' => false.
Loads of Thanks to #dkcwd
UPDATE: Let me summarise what exactly I am doing, I am trying to create a basic SOAP Server over SSL. Before making Web Services available on my Production website, I have to test it on Development system with has got Self Signed Certificate (Whose authentication is a problem right now).
Following are the problems I am facing in that regard:
When I try to call https://zendsoap.lan/Zend_Soap_server.php?wsdl its works fine I can view the wsdl.
But when I try https://zendsoap.lan/Zend_Soap_server.php, I get this:
SOAP-ERROR: Parsing WSDL: Couldn't load from 'https://zendsoap.lan/Zend_Soap_Server.php?wsdl' : failed to load external entity "https://zendsoap.lan/Zend_Soap_Server.php?wsdl"
Is that something I should be
The reason I made verify_peer=>false as I am running it on dev server so no need to verify my own created certificate, but obviously on production I want the Certificate to be verified.
This thing work fine with NuSoap but most of the stuff in NuSoap is deprecated for our server which is running PHP 5.4.6, So the most reliable solution for me using PHP's SOAP extension. And the reason for me using Zend is we're in process of moving our system from some third party framework to Zend Framework and everyday I get requests from client to add this & that new components, I assumed if I develop every new request from Client using Zend libraries then it will be easy for me in later stages to move to Zend Framework.
I hope I made some sense there.
Many Thanks in advance...