I am trying to download an external file using guzzle. This is the code that I use:
$url = 'https://testurl.net/dl/test.mp4?mime=true';
$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:
Client error: `GET https://testurl.net/dl/test.mp4?mime=true` resulted in a `403 Forbidden` response:
{"status":403,"msg":"download ISP is different to request ISP. request: AS20115 download: AS30083"}
I am not quite sure how to go about this and would really appreciate any help!
Seems that you are using https://openload.co/api#download-getlink to get a download link and download it then.
In this this I can assume that you hosting provider uses different IP for each outgoing HTTP request, and these IPs are even from different ASs (you think about them as "namespaces", check AS20115 and AS30083). And this particular site (openload.co) treats the situation like a security problem and prevents downloading (the second request).
There is nothing you can do on the application level. You have to talk to you ISP about it's routing rules. Maybe ask about (buy) a static IP address.
You can try to play around HTTP 1.1 keep-alive connections to send all requests through the same connection, but it depends on a server, and openload.co might not support this feature.
P.S. Please, include more details in questions in the future. Others are not wizards to read context from your mind :)
if you using vpn. please disable it
Related
I have a website which frequently makes SOAP calls to a particular API. The site was working fine for a few months of time, however the SOAP functionality suddenly stopped working without any known reason, the error was "Cannot connect to host".
The WSDL service has not moved or shut down.
After this I updated plesk from version 12 to version 17. SOAP client is still not working but now its a different error:
SOAP-ERROR: Parsing WSDL: Couldn't load from (URL) : failed to load external entity (URL)
This is my SOAP call:
$opts = array('http'=>array('user_agent' => 'PHPSoapClient'));
$context = stream_context_create($opts);
libxml_disable_entity_loader(false);
$client = new SoapClient($url,array('stream_context' => $context,'cache_wsdl' => WSDL_CACHE_NONE));
Any possible solutions?
EDIT:
New information came in, so the API server had DNS problems, how can I restore my connection to the API?
Your php server is clearly not reaching out the soap server. This might help:
Try checking directly from php server if the service are reachable:
wget {url} > page.txt
nano (or equivalent) page.txt
Try using other program to consume the server, I suggest Soap Ui
On the php server try ping the service url and see if the IP is resolved.
Check if any other soap service is reachable, you can use this service
If this not help you coming up with a solution, post here the results to help others solving it.
So I'm having a big issue and it protans to Socket.IO and the connection. The 'host' IP along with the port number I've entered does not want to connect. I've tried adding LocalHost, the plain IP Address, along with a variety of port numbers.
PHP Code:
var HOST = "/";
I solved the issue by doing this, but in the Chrome console, I get this error:
socket.io-1.4.5.js:1 POST http://192.168.1.222/socket.io/?EIO=3&transport=polling&t=LIjrKSc 404 (Not Found)
I have socket.io located like: template/js/new.js
I'm not entirely sure why this issue is occuring, I'm still going to do a little research, but if anyone has a solution to this, please inform me of so.
Thanks! ~mrgreen33gamer
Short form: I've got some PHP code that is uploading videos from my site to YouTube. I'm using the usual Google-provided PHP library, google-api-php-client. I have this code running on two servers; it works on one (https://www.example.com) but has suddenly stopped working on the other (https://dev.example.com), after a period of working nicely.
Details: The code doing the transfer is relatively standard, as far as I can tell: Once the libraries are loaded and some variables get some values, I'm doing:
$client = new Google_Client();
$client->setClientId($youtube_client_id);
$client->setClientSecret($youtube_client_secret);
$redirect = filter_var('https://example.com/upload-to-youtube', FILTER_SANITIZE_URL);
$client->setRedirectUri($redirect);
$youtube = new Google_YoutubeService($client);
$client->authenticate();
header('Location: ' . $redirect);
For the server that's not working, the $client->authenticate line throws the error:
Google_IOException: HTTP Error: (0) Problem with the SSL CA cert (path? access rights?) in Google_CurlIO->makeRequest() (line 128 of /var/www/html/example/includes/google-api-php-client/src/io/Google_CurlIO.php).
Other possibly-relevant details:
Back in the Developer's Console for my YT application, I have the following Redirect URIs set up:
https://dev.example.com/delete-from-youtube
https://dev.example.com/upload-to-youtube
https://www.example.com/delete-from-youtube
https://www.example.com/upload-to-youtube
According to the SSL certificate tester I found at https://www.sslshopper.com/ssl-checker.html, the certificates on both sites are visible and valid.
The certificate for dev.example.com is from Comodo; the certificate for www.example.com is from GeoTrust. I suppose I could try getting a new cert from GeoTrust, but I'd rather not spend the money unless I know it will fix the problem.
Both servers are running the same version of curl, if that's relevant.
It seems (to me) that the certificate and access to it should be OK (unless the certificate tester is wrong), so I don't understand where the complaint is coming from. The code and the server configuration has been unchanged for quite a while, hence my search for an external explanation. (I understand that these are Famous Last Words, but whatever.) Any thoughts out there? Thanks!
Potential duplicate question:
Amazon MarketplaceWebServiceOrders requests suddenly failing, PHP curl giving SSL CA cert error?
I had to restart the server, not just apache in order to solve the issue.
I've been trying to figure out what's wrong and what is the problem with this following PHP code, which is trying to make a SOAP call. I can't get it to work when I host the PHP on free web hosting sites
include_once("nusoap/lib/nusoap.php");
// create the client and define the URL endpoint
$client = new nusoap_client('http://xxxyyy.zzz:1881/');
// set the character encoding, utf-8 is the standard.
$client->soap_defencoding = 'UTF-8';
$client->call('sendSMS', array( 'uName' => 'kd81fg',
'uPin' => '18416',
'MSISDN' => '09156300965',
'messageString' => 'THIS IS A SAMPLE MESSAGE',
'Display' => '1',
'udh' => '',
'mwi' => '',
'coding' => '0' ),
"http://ESCPlatform/xsd");
When I tried using this hosted on my localhost, it work, but when I try to upload it (I tried so many free web hosting sites) to a web hosting site, and try to run it, it will not work.
I don't know what's wrong but I'm pretty sure that the code is perfect. I'm guessing that the free web hosting sites that I tried do not allow SOAP / XML , or maybe cURL is disabled, or url_fopen is Off on their php.ini (config) or something . I don't really know what's wrong right now and I need to finish what I'm doing right away.
UPDATE: I tried to echo what's the error and here what it says
HTTP Error: Couldn't open socket
connection to server http://xxxyyy.zzz:1881/, Error (111) Connection refused.
I checked the phpinfo for curl and stuff.
I was thinking of that too that maybe the problem is on the free hosts that they dont allow connection on port 1881, but I tried to scan and check if 1881 is open on my localhost, and it says my 1881 is closed, and now I'm confused.
Probadly port 1881 is closed on the free hosts. Try to close it on your pc/router. If the same error appears than this should be the problem.
EDIT: Did you check the phpinfo() for curl and stuff?
EDIT 2: Don't you have to add the client's host to your profile at the service provider's site like when you want to use the Google maps API?
Very often free web hosts will block outgoing ports. If you can set up a reverse proxy with apache or nginx (I'm assuming you're hosting the SOAP server).
I'm trying to do this in PHP. I need to check if a specified host is "up"
I thought of pinging the specified host (though I'm not sure how I would, since that would require root. --help here?)
I also though of using fsockopen() to try to connect on a specified port, but that would fail too, if the host wasn't listening for connections on that port.
Additionally, some hosts block ping requests, so how might I get around this? This part isn't a necessity, though, so don't worry about this too much. I realize this one might get tricky.
I typically do a simple cURL for a public page and see if it returns a 200. If you get a 500, 404, or anything besides a 200 response you know something fishy is up.
The short answer is that there is no good, universal way to do this. Ping is about as close as you can get (almost all hosts will respond to that), but as you observed, in PHP that usually requires root access to use the low port.
Does your host allow you to execute system calls, so you could run the ping command at the OS level and then parse the results? This is probably your best bet.
$result = exec("ping -c 2 google.com");
If a host is blocking a ping request, you could do a more general portscan to look for other open ports (but this is pretty rude, don't do it to hosts who haven't given you specific permission). Nmap is a good tool for doing this. It uses quite a few tricks to figure out if a host is up and what services may or may not be running. Be careful though, as some shared hosting providers will terminate your account for "hacking activity" if you install and use Nmap, especially against hosts you do not control or have permission to probe.
Beyond that, if you are on the same unswitched ethernet layer as another host (if you happen to be on the same open WiFi network, for example), an ethernet adaptor in promiscuous mode can sniff traffic to and from a host even if it does not respond directly to you.
You could use cURL
$url = 'yoururl';
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_NOBODY, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_exec($ch);
$retcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if (200==$retcode) {
// All's well
} else {
// not so much
}
For the host to be monitored at all, at least one port must be open. Is the host a web server? If so you could just open a connection to port 80, as long as it's opened successfully then at least some part of the host is working.
A better solution would be to have a script that is web accessible to just your monitor, and then you could open a connection to that, and that script would return various bits of system info.
EDIT--
How thorough do you want this test to be?
[server on] -> [apache running] -> [web application working]
Are all different levels of working. Just showing apache is returning something does at least show the server is on, but not that your web app is running.
(I realise that you may not be running anything like this but I hope it's a useful example)
EDIT--
Would it be worth installing a lightweight http server (I mean very light weight) just for monitoring?
Failing that could you install something on the hosts that phoned home every so often to show they are up?
I used gethostbyname($hostname).
The function gives you the IP if the host is up, or the input hostname if it couldn't find the IP.
if ($hostname !== gethostbyname($hostname)) {
//Host is up
}