Samuz Posted August 26, 2013 Share Posted August 26, 2013 (edited) This code works nice on my personal remote server and my local one. But I need it on another remote server. Here's code: function getVer($url) { $curl = curl_init($url); curl_setopt($curl, CURLOPT_NOBODY, true); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl, CURLOPT_FILETIME, true); $result = curl_exec($curl); if ($result === false) { die(curl_error($curl)); } $final = 1; $timestamp = curl_getinfo($curl, CURLINFO_FILETIME); if ($timestamp != -1) { //otherwise unknown $final = $timestamp; } else { $final = 1; } $test = substr($url, -2, 3); if($test == 'ss') : return str_replace('.css', '-'.$final.'.css', $url); elseif($test == 'js') : return str_replace('.js', '-'.$final.'.js', $url); endif; } If I attempt to it on this url getVer('http://static.trainingdragon.co.uk/assets/css/style.css') it doesn't work and returns an error 'couldnt connect to host'. I looked around and I was under the assumption this was cause the site was being blocked or something. Anyone have a hunch what the problem could be? But I can easily view that url in the browser with no problem Edited August 26, 2013 by Samuz Quote Link to comment https://forums.phpfreaks.com/topic/281571-weird-curl-problem/ Share on other sites More sharing options...
dalecosp Posted August 26, 2013 Share Posted August 26, 2013 Perhaps cURL isn't enabled? Works fine here in CLI. Lots of hosting companies have things like cURL and remote_url_fopen turned OFF ... and some of them won't let you turn it on, either... Quote Link to comment https://forums.phpfreaks.com/topic/281571-weird-curl-problem/#findComment-1446900 Share on other sites More sharing options...
.josh Posted August 27, 2013 Share Posted August 27, 2013 dalecosp: If they were turned off, he wouldn't have gotten the "could not connect" message. samuz: you answered your own question: the remote host blocked the request from the server your script was running on. It's possible the server's IP just happened to get caught up in some other range blacklisted by some filter (bot/spam prevention) but it's more likely the server's IP does have a history of being used by spammers/botters. Quote Link to comment https://forums.phpfreaks.com/topic/281571-weird-curl-problem/#findComment-1446912 Share on other sites More sharing options...
Samuz Posted August 27, 2013 Author Share Posted August 27, 2013 dalecosp: If they were turned off, he wouldn't have gotten the "could not connect" message. samuz: you answered your own question: the remote host blocked the request from the server your script was running on. It's possible the server's IP just happened to get caught up in some other range blacklisted by some filter (bot/spam prevention) but it's more likely the server's IP does have a history of being used by spammers/botters. Thanks for your reply. The thing is the file i'm trying to access is under a subdomain of the site the script is running from which confuses me even more, so they are on the same server - I know this for sure. And @dalecosp, the script works for other sites, just not this subdomain. Quote Link to comment https://forums.phpfreaks.com/topic/281571-weird-curl-problem/#findComment-1446913 Share on other sites More sharing options...
kicken Posted August 27, 2013 Share Posted August 27, 2013 I've encountered a small hand full of servers in the past that due to some kind of incorrect configuration have problem routing to themselves, you could be seeing something like that. If you have SSH access to the server, login and try grabbing the file with wget or the curl commandline tool. Check to make sure the domain resolves properly. Check the firewall rules to see if maybe there is a rule blocking the traffic. Quote Link to comment https://forums.phpfreaks.com/topic/281571-weird-curl-problem/#findComment-1446917 Share on other sites More sharing options...
snoopytamp Posted August 27, 2013 Share Posted August 27, 2013 I've encountered a small hand full of servers in the past that due to some kind of incorrect configuration have problem routing to themselves, you could be seeing something like that. If you have SSH access to the server, login and try grabbing the file with wget or the curl commandline tool. Check to make sure the domain resolves properly. Check the firewall rules to see if maybe there is a rule blocking the traffic. I've also encountered the same problem and like what kicken did, I checked the firewall. Found out that it was just the firewall blocking the traffic. Quote Link to comment https://forums.phpfreaks.com/topic/281571-weird-curl-problem/#findComment-1446918 Share on other sites More sharing options...
jazzman1 Posted August 27, 2013 Share Posted August 27, 2013 Not according nmap, port 22, 80 are opened from an external network. Also, I tried to run the script through bash shell and got a correct result. The problem is inside your php script, especially this line - curl_setopt($ch, CURLOPT_NOBODY, true); Never used "cURL" in php but try to run next script that I created for you: <?php $url = 'http://static.trainingdragon.co.uk/assets/css/style.css'; // Create a curl handle to a non-existing location $ch = curl_init($url); //curl_setopt($ch, CURLOPT_NOBODY, true); curl_setopt($ch, CURLOPT_FILETIME, true); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $out = curl_exec($ch); if($out === false) { echo 'Curl error: ' . curl_error($ch); } else { $fp = fopen('css/style.css', 'w'); fwrite($fp, $out); } // Close handle curl_close($ch); Quote Link to comment https://forums.phpfreaks.com/topic/281571-weird-curl-problem/#findComment-1446924 Share on other sites More sharing options...
Samuz Posted August 27, 2013 Author Share Posted August 27, 2013 No firewall rules have been set as far as I can see in cpanel. Also i'm going to contact the host to enable SSH for us and see how it goes from there. Not according nmap, port 22, 80 are opened from an external network. Also, I tried to run the script through bash shell and got a correct result. The problem is inside your php script, especially this line - curl_setopt($ch, CURLOPT_NOBODY, true); Never used "cURL" in php but try to run next script that I created for you: <?php $url = 'http://static.trainingdragon.co.uk/assets/css/style.css'; // Create a curl handle to a non-existing location $ch = curl_init($url); //curl_setopt($ch, CURLOPT_NOBODY, true); curl_setopt($ch, CURLOPT_FILETIME, true); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $out = curl_exec($ch); if($out === false) { echo 'Curl error: ' . curl_error($ch); } else { $fp = fopen('css/style.css', 'w'); fwrite($fp, $out); } // Close handle curl_close($ch); And I received the same cURL here: (couldn't connect to host) Quote Link to comment https://forums.phpfreaks.com/topic/281571-weird-curl-problem/#findComment-1446950 Share on other sites More sharing options...
jazzman1 Posted August 28, 2013 Share Posted August 28, 2013 (edited) When they enabled a SSH connection for you try to run your php script. If the problem is still there, you would run as @kicken said above cURL by shell terminal. It would be someting like: curl --verbose --output 'remote_style.css' 'http://static.trainingdragon.co.uk/assets/css/style.css' Edited August 28, 2013 by jazzman1 Quote Link to comment https://forums.phpfreaks.com/topic/281571-weird-curl-problem/#findComment-1447184 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.