Rob17 Posted May 7, 2009 Share Posted May 7, 2009 Hi all, Im v new to PHP and am having a problem on an opensource element of code. I know the code works as it was functioning on my old laptop before it went bang but i cannot get it working on my new laptop. The line of code is as follows: $xmlstr = sendRequest($path, $body); I've no doubt this is something I have setup incorrectly but if anyone could point me in the right direction that would be great. Thanks in advance. Rob Link to comment https://forums.phpfreaks.com/topic/157212-solved-sendrequest-problem/ Share on other sites More sharing options...
Rob17 Posted May 7, 2009 Author Share Posted May 7, 2009 SendRequest performs the following: function sendRequest($path, $body, $xml_only=true, $repeat=true) { global $amee_host,$amee_port,$responses; if(!isset($_SESSION["authToken"]) && strpos($path,"POST /auth")===false){ setAuthToken(); } $authToken=$_SESSION["authToken"]; $header = $path." HTTP/1.0\n" .getCookieLines() //insert cookies ."Accept: application/xml\n"; if($authToken!=null) $header.="authToken: ".$authToken."\n"; $header.="Host: ".$amee_host."\n" ."Content-Type: application/x-www-form-urlencoded\n" ."Content-Length: ".strlen($body)."\n" ."\n" .$body; //echo($header."<br/>"); $s = socket_create(AF_INET, SOCK_STREAM, 0); $z = socket_connect($s, gethostbyname($amee_host), $amee_port); socket_write ($s, $header, strlen($header)); $lines=array(); $lines[0]=""; $i=0; $xml_line=""; while (true) { $c = @socket_read($s, 1); echo($c); if ($c == "\n" || strlen($c)===0) { echo($lines[$i]."<br/>\n"); if(strpos($lines[$i],"Set-Cookie:")!==false) storeCookie($lines[$i]); else if(strpos($lines[$i],"<?xml")!==false) $xml_line=$lines[$i]; if(strlen($c)===0) break; $i++; $lines[$i] = ""; } else $lines[$i] .= $c; } socket_close($s); if(strpos($lines[0],"401 UNAUTH")!==false){//auth failed, try again, try ONCE at getting new authToken then trying again if($repeat===true){ debug("<p><b>Authentication failure - get new token and try again.</b></p>"); setAuthToken(); return sendRequest($path, $body, $xml_only, false); //try just one more time! } else debug("Authentication failure on second attempt."); } if($_SESSION["debugOn"]) $responses[count($responses)]=array("request"=>$header,"response"=>$lines); if($xml_only) return $xml_line; else return $lines; } //This function creates a new user profile and returns the 12 digit UID. function createNewProfile(){ $path = "POST /profiles"; $body = "profile=true"; try { $xmlstr = sendRequest($path, $body); } catch (Exception $e) { echo 'Caught exception: ', $e->getMessage(), "\n"; } Link to comment https://forums.phpfreaks.com/topic/157212-solved-sendrequest-problem/#findComment-828378 Share on other sites More sharing options...
Yesideez Posted May 7, 2009 Share Posted May 7, 2009 Do you get any error messages? TIP: When posting code if you surround it all with [code] and [/code] tags it preserves formatting and color codes everything for ease of reading. Link to comment https://forums.phpfreaks.com/topic/157212-solved-sendrequest-problem/#findComment-828379 Share on other sites More sharing options...
Rob17 Posted May 7, 2009 Author Share Posted May 7, 2009 Hi, The exact line this fails on is: $s = socket_create(AF_INET, SOCK_STREAM, 0); It doesnt through an error it just dies a death. Cheers, Rob Link to comment https://forums.phpfreaks.com/topic/157212-solved-sendrequest-problem/#findComment-828384 Share on other sites More sharing options...
Yesideez Posted May 7, 2009 Share Posted May 7, 2009 Not a command I'm familiar with. Only problem I've encountered with sockets is some web hosts block their use. You don't say whether you're running this via your new laptop on web hosting or whether you have Apache & PHP running on your laptop. Link to comment https://forums.phpfreaks.com/topic/157212-solved-sendrequest-problem/#findComment-828387 Share on other sites More sharing options...
Rob17 Posted May 7, 2009 Author Share Posted May 7, 2009 I'm running this on my local machine via IIS. I'm wondering if i've installed / setup php wrong Link to comment https://forums.phpfreaks.com/topic/157212-solved-sendrequest-problem/#findComment-828388 Share on other sites More sharing options...
Rob17 Posted May 7, 2009 Author Share Posted May 7, 2009 problem solved - had sockets commented out in php.ini...... DOH! Link to comment https://forums.phpfreaks.com/topic/157212-solved-sendrequest-problem/#findComment-828408 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.