fsockopen unable to connect error with remote css file

147 views Asked by At

I'm trying to get HTTP response headers of all images/css/js files used in a remote web page.When I use

fsockopen('mydomain.com',80,$errsno,$errstr,20)

it works.But when I try to do the same for a css link in my webpage, like,

fsockopen('mydomain.com/style.css',80,$errno,$errstr,20) 

it returns error

Warning: fsockopen(): php_network_getaddresses: getaddrinfo failed: No such host is known
Warning: fsockopen(): unable to connect to mydomain.com/style.css

Isn't it possible to connect to remote file like css or image files?

But the file is there in my server.I was hoping to get the response headers,file size,response time etc.Can't I do that this way? Any hint please?

1

There are 1 answers

2
Hartmut Holzgraefe On BEST ANSWER

fsockopen() doesn't speak HTTP, you'd have to write a valid HTTP request to the socket after opening it as in your first example yourself. Minimal form would be:

GET /style.css HTTP/1.1
Host: mydomain.com

followed by an extra empty line.

Or you could use PEAR HTTP_Request2 package if you don't want to speak raw HTTP:

http://pear.php.net/manual/en/package.http.http-request2.php