Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

PHP get_headers: failed to open stream

Posted on 2009-04-15
4
Medium Priority
?
3,453 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

604 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