Solved

PHP get_headers: failed to open stream

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
UPDATE query not working in mysqli php 8 51
javascript: add id amounts 5 47
php checkbox validation 5 27
comma true 6 33
Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
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.
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 dynamically set the form action using jQuery.

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