Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6254767
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T14:14:27+00:00 2026-05-24T14:14:27+00:00

I am attempting to load a webpage with file_get_contents(), and am running into problems.

  • 0

I am attempting to load a webpage with file_get_contents(), and am running into problems.

Basically, my web app will use the youtube data api to search for videos based on a user’s query, and then read each video’s youtube page to find information not provided by the api. I use file_get_contents() to read the youtube pages and then load the text into a DOM parser. Most of the time, this works like a charm. However, on occasion, I’ll get warnings saying that file_get_contents() returned an empty string (not for all videos, only for some of them). I know that the url I am providing is correct, because I echo a link to that url and it works as expected. I’ll refresh the page, reopen my browser, switch to a different browser, etc. but nothing will work. Then, I’ll leave the thing for an hour or two, come back to it, and it will magically work again!

Here is a snippet of my code:

function processNext($int) {
    // this function processes the next $int videos from the youtube data api response ($xmlDoc)
    global $xmlDoc;
    $begin = count($_SESSION["results"]) - $_SESSION["start"] + 1;
        /* $_SESSION["results"] is the array of already-processed videos
           $_SESSION["start"] and $_SESSION["end"] are the indexes of the first and last videos in the $xmlDoc
        */
    $end = count($_SESSION["results"]) - $_SESSION["start"] + $int;

    for ($i = $begin; $i <= $end; $i++) {
        $video = $xmlDoc->entry[$i];
        $doc = new DOMDocument();
        $doc->strictErrorChecking = FALSE;
        libxml_use_internal_errors(true);

        // this is the line that is causing me problems
        $doc->loadHTML(file_get_contents(getWatchURL(getVidID($video->id)))); 

        $doc = $doc->documentElement;

               // then, do some processing on the $doc

    }
}

Is it possible that file_get_contents() is timing out? Is cURL a better tool for what I am doing?

UPDATE: I get the same results with cURL.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T14:14:28+00:00Added an answer on May 24, 2026 at 2:14 pm

    Look at $http_response_header. You can check the status code of the request. If it’s anything other than 200, something has likely gone wrong. More about status codes.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Attempting to use XStream's JavaBeanConverter and running into an issue. Most likely I'm missng
I am attempting to load a dll into a console app and then unload
I'm attempting to load data from an undocumented API (OsiriX). Getting the NSManagedObject like
I'm attempting to load a dll into MSSQL with: USE dbname GO CREATE ASSEMBLY
I am attempting to load some json data into a custom JQuery function. There
Attempting to use the data series from this example no longer passes the JSONLint
I'm attempting to load JSON (from php's json_encode) into a Backbone JS collection. I've
I am attempting to load up an entire array of NSManagedObjects into an NSArray,
I'm attempting to embed the very convenient Google Translate translate element into a webpage,
asp.net c# Our webpage currently contains a rather large web app which causes a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.