Solved

PHP get_headers: failed to open stream

Posted on 2009-04-15
4
2,958 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
  • 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 125 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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Suggested Solutions

Introduction Many web sites contain image galleries; a common design for these galleries includes a page with a collection of thumbnail images.  You can click on each of the thumbnail images to see the larger version of the image.  This is easily i…
These days socially coordinated efforts have turned into a critical requirement for enterprises.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

757 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now