Today I set up some new PCs with Linux Mint and wanted to get my Magento-SOAP API run locally.
If I run the script:
$client = new SoapClient('http://magento.dev/mageapi/v2_soap/?wsdl', array('login' => 'apiuser', 'password' => '12345678', 'cache_wsdl' => WSDL_CACHE_NONE, 'trace'=>1))
I get an error that it can't reach http://schemas.xmlsoap.org/soap/encoding/
So I tried it with:
php -r "echo file_get_contents('http://schemas.xmlsoap.org/soap/encoding/');" -d allow_url_fopen=1
If I tun it trough the local network I get the warning:
PHP Warning: file_get_contents(http://schemas.xmlsoap.org/soap/encoding/):
failed to open stream: HTTP request failed! in Command line code on line 1
But If I run it through my mobile phone (via tethering) it works just fine.
It does not look like a network, but more like a local DNS-issue. On my MacBook and on my Windows device in the same network it's running fine.
Related
After running an apt upgrade and a restart of my ubuntu server, cUrl (via Guzzle) repots an error that the host cannot be resolved.
cURL error 6: Could not resolve host: xx.xx (see http:\/\/curl.haxx.se\/libcurl\/c\/libcurl-errors.html)
My code is
$client = new Client();
$response = $client->post("https://xx.xx?r=/center/api", [
RequestOptions::HEADERS => [
'X-Requested-With' => 'XMLHttpRequest'
]
]);
This happens randomly and with multiple domains. Meanwhile i was running pings for those domains on the terminal and they were working.
On StackOverflow and Google I could only find solutions that were adding the host to the hosts file but for me that seems to be not a real solution.
I have Windows-10 with Docker 18.06.0-ce-win72 (19098).
In our network uses NTLM-proxy, so docker goes to the Internet through Ntlmaps (I also try Cntlm, result is the same).
I run image based on php:7.2-fpm with docker-compose.
I enter the conteiner
docker exec -it {id} bash
and run command:
curl https://packagist.org/packages.json // works!
or
wget https://packagist.org/packages.json // works!
But
php -r "echo file_get_contents('https://packagist.org/packages.json');"
results "failed to open stream: Cannot assign requested address in Command line code on line 1"
curl https://packagist.org/packages.json ----> works
php -r "echo file_get_contents('https://packagist.org/packages.json');" ----------> fails to open stream
php -r "echo curl_exec(curl_init('https://packagist.org/packages.json'));" ---------> works
I see ntlmaps-console and view request from "curl", but it's no requests in console from "file_get_contents".
In php allow_url_open => on
I found similar problem: https://github.com/composer/composer/issues/2169
But I can't disable IPv6 in Docker for test the solution.
I try run "sysctl", but "bash: sysctl: command not found"
I try set
sysctls:
- net.ipv6.conf.all.disable_ipv6=1
- net.ipv6.conf.default.disable_ipv6=1
- net.ipv6.conf.lo.disable_ipv6=1
in docker-compose.yml for service, but it didn't solve the problem
I run this container on VPS and this work on VPS.
How can I solve this problem on Windows + NTLM?
My docker-compose.yml: https://pastebin.com/PfsgzrLs
Solution for file_get_contents():
$context = stream_context_create([
'http' => [
'proxy' => 'tcp://10.0.75.1:3112', // 3112 - proxy port on host-mashine
'request_fulluri' => true
]
]);
echo file_get_contents('https://ya.ru', false, $context);
I have been transferring my PHP server files from windows to ubuntu 14.04 and my script broke...
I'm getting the error when downloading from S3.
$result = $s3->getObject(array(
'Bucket' => AWS_S3_BUCKET,
'Key' => $imgName,
'SaveAs' => $targetPath
)); //the exception is thrown!
The exception message:
Error executing GetObject on http://s3.amazonaws.com/bucket/file AWS
HTTP error: Unable to open ../../downloads/file using mode r+:
fopen(../../downloads/file).
sudo chmod -R 777 wwwfolder didn't work
Any ideas?
** Update **
Found a Hax/Workaround.... adding touch($targetPath) before $s3->getObject method fixes the problem... but why? I tried on different ubuntu server (same version) and there it works (without touch; and i don't know how it was configured..).
What about now? Any ideas?
I have simple script connection call using PHP 5.2.10 to a Web service working with SOAP 1.2.
The same PHP installation is able to connect via Web service to another web server working with SOAP 1.1 without issues. In addition, the web services using 1.2 is working fine with another two servers using almost the same hard code.
However, every time I am using SOAP 1.2 on this server with PHP 5.2.10 I got the bellow error if I run the script from a batch file:
Warning: SoapClient::SoapClient(http://www.w3.org/2005/05/xmlmime): failed to open stream: HTTP request failed! HTTP/1.1 401 Authorization Required in C: \NewSimpleConnectionTest.php on line 10
If the script is running via Eclipse PHP with PHP 5.2 on a different computer, it does not have any error so the hard code seems fine, user and password are correct too because it is used on the others servers and on the Eclipse test:
My script is this:
<?php
$_endpoint = "http://server:8080/serverv/ServerAPI";
$_username = "userServer";
$_password = "123ABC!";
try
{
$client = new SoapClient($_endpoint."?WSDL", array('location' => $_endpoint, 'login' => $_username, 'password' => $_password, 'trace' => 1, 'features' => SOAP_USE_XSI_ARRAY_TYPE + SOAP_SINGLE_ELEMENT_ARRAYS, 'soap_version' => SOAP_1_2));
echo 'Connected to Web Services.';
}catch(Exception $e){
echo 'Failure to connect to WebServices.';
}
?>
This is the information in the SOAP and XML phpinfo.
SimpleXML
Simplexml support => enabled
Revision => $Revision: 1.151.2.22.2.46 $
Schema support => enabled
soap
Soap Client => enabled
Soap Server => enabled
Directive => Local Value => Master Value
soap.wsdl_cache => 1 => 1
soap.wsdl_cache_dir => /tmp => /tmp
soap.wsdl_cache_enabled => 1 => 1
soap.wsdl_cache_limit => 5 => 5
soap.wsdl_cache_ttl => 86400 => 86400
Any idea about what is missing or the problem on this PHP version to work with SOAP 1.2 in that server?
Thanks in advance!!
After some hours working around this problem, the solution was changing the version of PHP from 5.2.10 to 5.5.28.
There is some kind of bug on this old version and prevent the correct connection with SOAP 1.2.
I hope this help someone using this old version of PHP.
I have configured the openssl with wamp (Apache server). But while I using gdata api I'm getting following error.
( ! ) Fatal error: Uncaught exception 'Zend_Http_Client_Adapter_Exception' with message ' in C:\Zend_1_11_11\library\Zend\Http\Client\Adapter\Socket.php on line 234
( ! ) Zend_Http_Client_Adapter_Exception: Unable to Connect to ssl://accounts.google.com:443. Error #10060: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond. in C:\Zend_1_11_11\library\Zend\Http\Client\Adapter\Socket.php on line 234
Somebody help me on this...
Solution only for Windows users:
Check the SSL module is enabled in php.ini:
extension=php_openssl.dll
Answer from Mikhail does not work for me as I run it in Alpine Linux and .dll is only windows extension. Do not use it outside of Windows, it only adds warnings.
Solved my problem:
I had a self-signed certificate that was unable to establish connection.
To check that it is problem you can make a request:
wget way:
// not working:
wget https://accounts.google.com:443
// working:
wget https://accounts.google.com:443 --no-check-certificate
or curl way:
// not working:
curl https://accounts.google.com:443
// working:
curl https://accounts.google.com:443 -k
To temporary solve it in my dev docker container, I have added use of curl adapter and no check for certificate to the code:
$config = array(
'adapter' => 'Zend_Http_Client_Adapter_Curl',
'curloptions' => [CURLOPT_SSL_VERIFYPEER => false, CURLOPT_SSL_VERIFYHOST => false]
);
$client = new Zend_Http_Client('https://example.com', $config);
You are behind proxy, so you can not connect directly.Try to use Zend/Http/Client/Adapter/Proxy.php instead of Zend\Http\Client\Adapter\Socket.php
If you on Ubuntu try add in your php.ini
openssl.capath=/etc/ssl/certs
For more info read this issue