// PHP POST数据的三种方法
// php有三种方法可以post数据,分别为Curl、socket、file_get_contents:
/**
* Socket版本
* 使用方法:
* $post_string = "app=socket&version=beta";
* request_by_socket('facebook.cn','/restServer.php',$post_string);
*/
function request_by_socket($remote_server, $remote_path, $post_string, $port = 80, $timeout = 30)
{
$socket = fsockopen($remote_server, $port, $errno, $errstr, $timeout);
if (!$socket) die("$errstr($errno)");
fwrite($socket, "POST $remote_path HTTP/1.0rn");
fwrite($socket, "User-Agent: Socket Examplern");
fwrite($socket, "HOST: $remote_serverrn");
fwrite($socket, "Content-type: application/x-www-form-urlencodedrn");
fwrite($socket, "Content-length: " . (strlen($post_string) + 8) . 'r