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 6567919
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T14:23:38+00:00 2026-05-25T14:23:38+00:00

I have written a PHP script on my local server to loop through an

  • 0

I have written a PHP script on my local server to loop through an array of movie titles and, using http://www.imdbapi.com/, pull down associated metadata.

for ($i=0; $i < count($files['Film']); $i++) { 
    // get data from IMDB based on file title
    $imdb_data = json_decode(file_get_contents('http://www.imdbapi.com/?t='.urlencode($files['Film'][$i]['title'])), true);

    // save poster image
    $img_name = trim(strtolower($imdb_data['Title'])).'.jpg';
    file_put_contents('img/posters/'.$img_name, file_get_contents($imdb_data['Poster']));

    // set film data
    $files['Film'][$i]['year'] = $imdb_data['Year'];
    $files['Film'][$i]['runtime'] = $imdb_data['Runtime'];
    $files['Film'][$i]['rating'] = $imdb_data['Rating'];
    $files['Film'][$i]['summary'] = $imdb_data['Plot'];
    $files['Film'][$i]['image'] = $img_name;
    $files['Film'][$i]['location_id'] = $this->data['Film']['location_id']; 
}

I hit the php max_execution_time on the line that starts file_put_contents. I’ve noticed that a few images do get downloaded and I also get an incomplete image so I’m guessing I hit the time limit when downloading images.

What can I do to improve my script to prevent this? I don’t really like the workaround of increasing the time limit if there’s something fundamental I can to that will optimize the script.

  • 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-25T14:23:39+00:00Added an answer on May 25, 2026 at 2:23 pm

    This is mostly a copy paste from a project (loading data from mysql asynchronously) I was working some month ago. I changed it a little bit to your needs, I have put some comments for you, and creted a new file (getData.php).

    I haven’t gone exactly in detail with downloading movies, however it downloads an image, and uploads it, pretty much the same process, hope you can adjust it to your needs.

    put these two file in a directory and run index.php

    This is the firs file: index.php

        <html>
        <head>
        <script type="text/javascript">
    
        var request = false;
        try { 
          request = new XMLHttpRequest(); 
        } catch (trymicrosoft) {                         
          try { 
            request = new ActiveXObject("Msxml2.XMLHTTP"); 
          } catch (othermicrosoft) {
            try {
              request = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (failed) {                  
              request = false;       
            }
          }
        }
    
        if (!request) 
          alert("Error initializing XMLHttpRequest!"); 
        </script>
    
        <script type="text/javascript">
           function getData() 
           {
    
            //inform the user for to wait a little bit
            var txt=document.getElementById("messageBox")
            txt.innerHTML="Please wait for the image to download...";
    
                //we will call asychronously getData.php 
                var url = "getData.php";
                var params = "";//no url parameters
    
                request.open("POST", url, true);//use post for connect harder to attack, lots of data transfer 
    
                //Some http headers must be set along with any POST request.
                request.setRequestHeader("Content-type", "application/x-www-form-urlencoded;charset=utf-8");
                request.setRequestHeader("Content-length", params.length);
                request.setRequestHeader("Connection", "close");
    
                request.onreadystatechange = updatePage;
                request.send(params);
    
           }////////////////////
    
           //You're looking for a status code of 200 which simply means okay.
           function updatePage() {
             if (request.readyState == 4) {
               if (request.status == 200) 
               {  
                    //getData.php sends as the image size, get it
                    var r=request.responseText.split("$");//$ is a custom data separator I use  
    
                    //inform the user
                    var txt=document.getElementById("messageBox")
                    txt.innerHTML="The file was downloaded! Its size is:"+r[0]+"x"+r[1]+" the name is:"+r[2];
    
                    /*r is a javascript array, 0=width, 1=height, 2=file name
                    */
    
                    //display the image 
                     document.getElementById("imageBox").style.width = r[0] + 'px';
                     document.getElementById("imageBox").style.height = r[1] + 'px';
                    document.getElementById("imageBox").style.backgroundImage = "url("+r[2]+")";
    
               } 
               else{
                 //alert("status is " + request.status);
                 }
             }
           }
    
        </script>
        </head>
        <body onload="getData();">
    
        <div id='messageBox'></div>
        <div id='imageBox'></div>
    
    <font color=red>
        You see I am under the image but I am already loaded cause 
        I don't have to wait for the image to load cause it loads asychronously.
        Whenever the image is ready the xmlhttp mechanism will let the page
        know and the associated javascript function will update the dom and will
        update the page without reloading it!
        </font>
        </body>
        </html>
    

    This is the second file getData.php

    <?PHP
    
    //make a name for the file
    $file_name = rand(1,9999).'.jpg';
    
    //download the file
    file_put_contents($file_name, file_get_contents('http://chachatelier.fr/programmation/images/mozodojo-original-image.jpg'));
    
    
    //get the size of the image
    $size = getimagesize($file_name);
    
    
    //send asycnhronously the width, height, and the name
    echo $size[0],'$',$size[1],'$',$file_name;
    
    ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have written a script using my local PHP 5.3 installation making use of
I have written a webservice using the PHP SOAP classes. It has functions to
I have written a PHP script that checks whether a domain is available for
I have written a PHP script which generates an SQL file containing all tables
I have written a php script that generates a list of links that match
I have a PHP script which calls methods from a class I have written.
I am a newbie in php, mysql. I have written a hello.php script, which
I have a site written in PHP utilizing PDO. I am using the bindParam()
I need to transfer data from a PHP script on my local server to
I have written a PHP script that I would like to use on several

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.