erics1024 Posted May 12, 2009 Share Posted May 12, 2009 Basically, when I attempt to return a page from my server's WHM panel and specify the URL directly in the cURL code it works fine. Example: $ch1 = curl_init("http://domain.com:2086/xml-api/fetchsslinfo?crtdata=$cert"); This spits back out the page that would show up there, and even if I pass a variable in through $cert, it works fine. It's actually able to return exactly what I want it to, a XML page of information about the cert I just sent. When I attempt to execute the same thing, but by passing (what was domain.com above) into the URL with a variable, it's almost as if cURL doesn't even execute. Example: $url = sprintf('http://%s:2086/xml-api/fetchsslinfo?crtdata=%s', $svr, $cert); $ch1 = curl_init($url); This only happens when the variable that goes into the domain part of the URL was passed in through stdin. If I define it manually (see below) it works fine. $svr2 = 'mydomain.com'; $url = sprintf('http://%s:2086/xml-api/fetchsslinfo?crtdata=%s', $svr2, $cert); $ch1 = curl_init($url); This, on the other hand, does not work, even if I enter the EXACT same string as the domain. $svr2 = fgets(STDIN); $url = sprintf('http://%s:2086/xml-api/fetchsslinfo?crtdata=%s', $svr2, $cert); $ch1 = curl_init($url); For testing purposes, I added the following to my code: if(!$acctinfo = curl_exec($ch1)){ echo "errno: " . curl_errno($ch1) . "\n"; echo "errmsg: " . curl_error($ch1) . "\n";} echo "acc 411: $acctinfo" . "\n"; echo "URL:$url" . "\n"; echo "server stdin: $svr2" . "\n"; echo "server cfgd: $svr" . "\n"; In this case, I've got $svr defined as my domain name elsewhere in the script, and that's what makes it into the formatted URL. $svr2 is what we get from stdin. When they get echoed, they both appear to be exactly the same. Additionally, the URL made with the stdin hostname, and the one made by the "defined in script" hostname are exactly the same. There is no doubt or question that STDIN is grabbing the text I enter, and is storing it as the right variable, as I am able to see the text when I echo the var, and it looks 100% correct(identical to the text string that works.) I get the following cURL errors when I run the script: errno: 6 ; No data record of requested typetrader.net <<trader.net happens to be the last part of my domain name. Error #6 means "COULDNT_RESOLVE_HOST." Are we really looking for "trader.net" records in the zonefile instead of "A" records? 0o The above is produced by the code echo "errno: " . curl_errno($ch1) . "\n"; echo "errmsg: " . curl_error($ch1) . "\n"; Notice that the error message is supposed to have the string "errmsg: " before it, but it is mysteriously left off. This issue happens exactly the same way when trying to query other URLs, even when simply going to google, I run into this problem. If I define the hostname manually in the script, it works fine. If I assign the input from stdin to a variable, and use that as the hostname in the URL, it doesn't work. This holds true with any URL/hostname I've tried. Only when I pass the entire URL (including a trailing slash - doesn't work without one when going through stdin, but works fine when I define manually it and pass it into cURL without http:// or the trailing slash.) into stdin will it allow me to see the page contents. This is despite having CURLOPT_FOLLOWLOCATION enabled. I've never run into a problem like this doing PhP development w/ Apache, but I've also never used stdin with PhP. What am I missing here? Link to comment https://forums.phpfreaks.com/topic/157790-phpclibug-curl-doesnt-like-stdin-but-works-otherwise/ Share on other sites More sharing options...
erics1024 Posted May 12, 2009 Author Share Posted May 12, 2009 As it turns out, STDIN takes in the new line character created when you hit enter in the command window, which was causing the DNS resolver to do some weird stuff. Solved by adding this: $svr2 = fgets(STDIN); $svr2 = urlencode($svr2); list($svr2, $crap) = explode('%', $svr2); Link to comment https://forums.phpfreaks.com/topic/157790-phpclibug-curl-doesnt-like-stdin-but-works-otherwise/#findComment-832221 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.