Checking is a remote page exists

I’m writing a script where I need to check if a url actually works. I tried something like

url works

However, for some reason when url does not work it times out.

Is there a better and faster way to do this? I’m pretty new to php so please keep the words simple :)

had a simular prob a while ago.

to get the timout handled u can use stream_set_blocking($fp,0) and check the strlen() of the value returned by fgetc()/fgets().

sounds compicated but isn’t.

  1. set a filepointer to ur url: $fp=fopen($url)
  2. call stream_set_blocking($fp,1); the second parameter is the timeout in seconds (how long ur php-script should try to read the url befor giving up)
  3. get the content (one char should be enough): $content=fgetc($fp);
  4. and then just check if there was content returned if(strlen($content))

that means:
/* url works*/

but that don’t tell u more about the url than that there is content returned.

detaild desc of the functions:

Sponsor our Newsletter | Privacy Policy | Terms of Service