Results 1 to 9 of 9

Thread: PHP: fopen() and fread()

  1. #1

    PHP: fopen() and fread()

    hi,

    in my application there is a code block that looks something like this:

    PHP Code:
    $fp fopen($rssURL,"r"
     
    while (
    $data fread($fp4096))
    {
        
    //process data

    the $rssURL is the location of an rss file on some website's server.

    so my question is: when does fopen() and/or fread() time out? is there any way to detect this? i don't want my script to sit there for hours trying to open one 2K file? can i set the limit?

    thanks

  2. #2
    php has it's max execution time - 30s
    after this time, script is stopped

    btw
    i prefer usign
    PHP Code:
    file_get_contents ($rssURL); 
    than fopen () + fread ()

  3. #3
    yeah but i want to stop trying to open the file after about a second or two...ya know?

  4. #4

    here it goes (not sure if working):
    PHP Code:
    <?php

    $rssURL 
    "ulr_gose_here";
    $maxtime 3//3 seconds in this case
    $time_start time ();

    if (@
    $fp fopen ($rssURL"r")) {
        while (
    $data fread ($fp4096) && (time () - $time_start) < $max_time) {
            
    //process data
        
    }
    }

    ?>
    edit: fixed "fopen" statement

  5. #5
    it needs to be on the fopen()...

    let's say the site with the RSS file i'm trying to pull is down. then i obviuosly can't pull the RSS file. it's weird though because it doesn't cause an error and die. it just sits there.

    ?

  6. #6
    better?

  7. #7
    better...what?

  8. #8
    look @ the code AGAIN...

  9. #9
    You may want to consider launching a CRON script that pulls the data and caches it locally, and then using your web code to parse the script once it's already on the filesystem.

    This has a few advantages -
    1) It doesn't slam their server if your server is busy.
    2) It doesn't hang your site if their server is down.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

Home About kirupa.com Meet the Moderators Advertise

 Link to Us

 Credits

Copyright 1999 - 2012