How to delay INSERT time?

Discussion in 'PHP' started by youlichika, Oct 27, 2010.

  1. #1
    I'm using simplepie. I want to store the rss feeds items into mysql database.
    I've been parsing every RSS items into $link,$title,$date,$content.
    But simplepie get the rss feeds from its resource need few seconds and insert into just one moment, that cause it always stores first few lows of RSS items, not all of them.
    How to delay INSERT time that can store all of the rss items into mysql database?TXS
     
    youlichika, Oct 27, 2010 IP
  2. jestep

    jestep Prominent Member

    Messages:
    3,659
    Likes Received:
    215
    Best Answers:
    19
    Trophy Points:
    330
    #2
    PHP is a syncronous language. That means it performs step 1, and then step 2, and then step 3. It is very difficult to instruct it to do step 1, 2 and 3 all at the same time. What you're suggesting doesn't really mesh with the way php works.

    Fetch feed
    Parse feed
    Insert data

    You can't even start parsing until the feed is completely read. You can insert while you're parsing with a loop, but the feed must me fully fetched. I would bet that there is a problem with the coding and not with the script needing more time to get the rss feed.
     
    jestep, Oct 27, 2010 IP
  3. youlichika

    youlichika Greenhorn

    Messages:
    74
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    16
    #3
    Thanks, maybe you are right "there is a problem with the coding".
    I changed another rss feed url, it has 20 feeds items.
    I run my script first time, it inserted 7 items into database. Then when I empty the database and run the script second time, it inserted 10 items into database.
    the insert number is not stable, but it always can not insert all of them.

    I can not check the wrong problem out.
     
    youlichika, Oct 27, 2010 IP
  4. jestep

    jestep Prominent Member

    Messages:
    3,659
    Likes Received:
    215
    Best Answers:
    19
    Trophy Points:
    330
    #4
    Can you post the code for fetching and parsing the feed?
     
    jestep, Oct 27, 2010 IP
  5. youlichika

    youlichika Greenhorn

    Messages:
    74
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    16
    #5
    Hi, I added echo behind insert for check, then compared the results. I find something. When the article has ' or " ,I can not find them in the database. The quotation mark made the mistake.
    Maybe I should add some:
    $str = preg_replace('/\'/', "\'", $str);
    $str = preg_replace('/\"/', '\"', $str);

    Thanks, I'm continuing my test. Late I will tell you results.
     
    youlichika, Oct 27, 2010 IP
  6. youlichika

    youlichika Greenhorn

    Messages:
    74
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    16
    #6
    Yes, the problem is it.
    Thanks, I think now can close the thread.
     
    youlichika, Oct 28, 2010 IP
  7. kasun0777

    kasun0777 Well-Known Member

    Messages:
    355
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    138
    #7
    Yes, Close the thread
     
    kasun0777, Oct 28, 2010 IP