Solved

PHP get_headers: failed to open stream

Posted on 2009-04-15
4
3,226 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 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

Why Off-Site Backups Are The Only Way To Go

You are probably backing up your data—but how and where? Ransomware is on the rise and there are variants that specifically target backups. Read on to discover why off-site is the way to go.

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…
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…
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 …

691 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