You cannot open a connection directly to a path on a remote host using fsockopen
. The url www.mydomain.net/1/file.php
contains a path, when the only valid value for that first parameter is the host, www.mydomain.net
.
If you are trying to access a remote URL, then file_get_contents() is your best bet. You can provide a full URL to that function, and it will fetch the content at that location using a normal HTTP request.
If you only want to send an HTTP request and ignore the response, you could use fsockopen()
and manually send the HTTP request headers, ignoring any response. It might be easier with cURL though, or just plain old fopen(), which will open the connection but not necessarily read any response. If you wanted to do it with fsockopen()
, it might look something like this:
$fp = fsockopen("www.mydomain.net", 80, $errno, $errstr, 30);
fputs($fp, "GET /1/file.php HTTP/1.1
");
fputs($fp, "Host: www.mydomain.net
");
fputs($fp, "Connection: close
");
That leaves any error handling up to you of course, but it would mean that you wouldn't waste time reading the response.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…