我正在尝试让 stream_socket_client 与代理服务器一起工作。
代码和平:
<?php
$context = stream_context_create(['http' => ['proxy' => '147.135.210.114:54566', 'request_fulluri' => true]]);
//$file = file_get_contents("http://www.google.com", false, $context);
$fp = stream_socket_client("tcp://www.google.com:80", $errno, $errstr, 30, STREAM_CLIENT_CONNECT, $context);
if (!$fp) {
echo "$errstr ($errno)<br />\n";
} else {
fputs($fp, "GET / HTTP/1.0\r\nHost: www.google.com\r\nAccept: */*\r\n\r\n");
while (!feof($fp)) {
echo fgets($fp, 1024);
}
fclose($fp);
}
?>
而 file_get_contents 使用代理 (tcpdump -i any -A host 114.ip-147-135-210.eu) stream_socket_client 只是忽略它并直接转到 google.com。我究竟做错了什么?我的最终目标是通过代理连接到 RabbitMQ(AMQP 协议),但我什至无法让简单的 HTTP 连接正常工作。