?
Solved

PHP get_headers: failed to open stream

Posted on 2009-04-15
4
Medium Priority
?
3,295 Views
Last Modified: 2012-05-06
For validating URL's I want to retrieve the headers (so I can check the HTTP code, 404 etc). But I can't even get the headers. The lines below result in this error:


Warning: get_headers(http://www.php.net) [function.get-headers]: failed to open stream: A connection attempt failed because the connected party did not properly respond after a certain time, or the connection failed because the connected host did not reply in c:\www\test.php

Fatal error: Maximum execution time of 30 seconds exceeded in c:\www\test.php
<?php
$url = 'http://www.example.com';
print_r(get_headers($url, 1));
?>

Open in new window

0
Comment
Question by:Kazung-Q
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 8

Expert Comment

by:mostart
ID: 24145937
Well your error message uncovers it already. The remote script you tried to get headers from did not answer before your 30 seconds timeout was hit.
Check the following:

Is the requested URL valid ? (does it work in your browser ?)
Do you have connection from your php server to the requested URL (Firewall ?)
0
 

Author Comment

by:Kazung-Q
ID: 24145979
both yes: the website is valid (and I tried with other websites too) and I can reach it via my browser.

But I am behind a proxy. Could that be a cause? How does PHP connect?
0
 
LVL 8

Accepted Solution

by:
mostart earned 500 total points
ID: 24146246
ok this is most probably the solution. Since you need a proxy to get WWW access you can't connect through PHP.
Now you have two possible ways to solve this:

1.) Convince your administrator to grant direct http access to the requested URL.

2.) Use a proxy with PHP which is not so simple. This link will help you though:
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/Q_21202785.html?sfQueryTermInfo=1+10+php+proxi+through
0

Featured Post

WordPress Tutorial 2: Terminology

An important part of learning any new piece of software is understanding the terminology it uses. Thankfully WordPress uses fairly simple names for everything that make it easy to start using the software.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
This article discusses how to implement server side field validation and display customized error messages to the client.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question