Created
February 25, 2010 17:17
-
-
Save banyan/314746 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // cackPHP cake_1.2.3.8166/cake/libs/socket.php | |
| 96 /** | |
| 97 * Connect the socket to the given host and port. | |
| 98 * | |
| 99 * @return boolean Success | |
| 100 * @access public | |
| 101 */ | |
| 102 function connect() { | |
| 103 if ($this->connection != null) { | |
| 104 $this->disconnect(); | |
| 105 } | |
| 106 | |
| 107 $scheme = null; | |
| 108 if (isset($this->config['request']) && $this->config['request']['uri']['scheme'] == 'https') { | |
| 109 $scheme = 'ssl://'; | |
| 110 } | |
| 111 | |
| 112 if ($this->config['persistent'] == true) { | |
| 113 $tmp = null; | |
| 114 $this->connection = @pfsockopen($scheme.$this->config['host'], $this->config['port'], $errNum, $errStr, $this->config['timeout']); | |
| 115 } else { | |
| 116 $this->connection = @fsockopen($scheme.$this->config['host'], $this->config['port'], $errNum, $errStr, $this->config['timeout']); | |
| 117 } | |
| 118 | |
| 119 if (!empty($errNum) || !empty($errStr)) { | |
| 120 $this->setLastError($errStr, $errNum); | |
| 121 } | |
| 122 | |
| 123 return $this->connected = is_resource($this->connection); | |
| 124 } | |
| // xmlrpc-2.2.2/lib/xmlrpc.inc | |
| 1337 $op= 'POST ' . $uri. " HTTP/1.0\r\n" . | |
| 1338 'User-Agent: ' . $GLOBALS['xmlrpcName'] . ' ' . $GLOBALS['xmlrpcVersion'] . "\r\n" . | |
| 1339 'Host: '. $server . ':' . $port . "\r\n" . | |
| 1340 $credentials . | |
| 1341 $proxy_credentials . | |
| 1342 $accepted_encoding . | |
| 1343 $encoding_hdr . | |
| 1344 'Accept-Charset: ' . implode(',', $this->accepted_charset_encodings) . "\r\n" . | |
| 1345 $cookieheader . | |
| 1346 'Content-Type: ' . $msg->content_type . "\r\nContent-Length: " . | |
| 1347 strlen($payload) . "\r\n\r\n" . | |
| 1348 $payload; | |
| 1349 | |
| 1350 if($this->debug > 1) | |
| 1351 { | |
| 1352 print "<PRE>\n---SENDING---\n" . htmlentities($op) . "\n---END---\n</PRE>"; | |
| 1353 // let the client see this now in case http times out... | |
| 1354 flush(); | |
| 1355 } | |
| 1356 | |
| 1357 if($timeout>0) | |
| 1358 { | |
| 1359 $fp=@fsockopen($connectserver, $connectport, $this->errno, $this->errstr, $timeout); | |
| 1360 } | |
| 1361 else | |
| 1362 { | |
| 1363 $fp=@fsockopen($connectserver, $connectport, $this->errno, $this->errstr); | |
| 1364 } | |
| 1365 if($fp) | |
| 1366 { | |
| 1367 if($timeout>0 && function_exists('stream_set_timeout')) | |
| 1368 { | |
| 1369 stream_set_timeout($fp, $timeout); | |
| 1370 } | |
| 1371 } | |
| 1372 else | |
| 1373 { | |
| 1374 $this->errstr='Connect error: '.$this->errstr; | |
| 1375 $r=&new xmlrpcresp(0, $GLOBALS['xmlrpcerr']['http_error'], $this->errstr . ' (' . $this->errno . ')'); | |
| 1376 return $r; | |
| 1377 } | |
| 1378 | |
| 1379 if(!fputs($fp, $op, strlen($op))) | |
| 1380 { | |
| 1381 fclose($fp); | |
| 1382 $this->errstr='Write error'; | |
| 1383 $r=&new xmlrpcresp(0, $GLOBALS['xmlrpcerr']['http_error'], $this->errstr); | |
| 1384 return $r; | |
| 1385 } | |
| 1386 else | |
| 1387 { | |
| 1388 // reset errno and errstr on succesful socket connection | |
| 1389 $this->errstr = ''; | |
| 1390 } | |
| 1391 // G. Giunta 2005/10/24: close socket before parsing. | |
| 1392 // should yeld slightly better execution times, and make easier recursive calls (e.g. to follow http redirects) | |
| 1393 $ipd=''; | |
| 1394 do | |
| 1395 { | |
| 1396 // shall we check for $data === FALSE? | |
| 1397 // as per the manual, it signals an error | |
| 1398 $ipd.=fread($fp, 32768); | |
| 1399 } while(!feof($fp)); | |
| 1400 fclose($fp); | |
| 1401 $r =& $msg->parseResponse($ipd, false, $this->return_type); | |
| 1402 return $r; | |
| 1403 | |
| 1404 } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment