title: Run a heavy PHP script that inserts data to Wordpress database
body: <p>I have a problem running a PHP script that gets data from an external API that's returning image links and storing them as Wordpress posts using the <code>wp_insert_post()</code> method. </p>
  
  <p>The problem is that the data is massive and the browser is crashing after running the script.</p>
  
  <p>This is my script:</p>
  
  <pre><code>    &lt;?php
  
  $ch = curl_init();
  
  
  curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
  curl_setopt($ch, CURLOPT_URL, 'https://myapi.com/name');
  $result = curl_exec($ch);
  curl_close($ch);   
  
  
  $objectCh = json_decode($result,true);
  
  
  $ch2 = curl_init();
  
  
  for($i=0;$i &lt; 20;$i++){
  
      $url = 'https://www.myapi.com/api/images/'.$objectCh[chapters][$i][3].'/';
  
  
  
  
  
  
  
              curl_setopt($ch2, CURLOPT_URL,$url );
  
              $result = curl_exec($ch2);
  
              $object = json_decode($result,true);
  
  
  
                      for($i=0;$i &lt; count($object[images]);$i++){
  
  
  
  
                          $comic = array (
                              'post_content'=&gt; "&lt;img src=\""$object[images] 
                              [$i][1])"&gt;",
                              'post_title' =&gt; 'Chapeter 2 !!',
                              'post_status'           =&gt; 'publish',
  
  
  
                          );
  
                          wp_insert_post( $comic,true );
                        /*  echo ($object[images][$i][1]);
  
                          echo "&lt;br&gt;";*/
  
                          }
  
  
  
  
      }
      curl_close($ch2);  
  </code></pre>
  
  <p>This is the script I figured out that runs the script many times and changes the script value, but still the browser is crashing. Is there any way to run this program without it crashing? </p>
  
  <p>I'm using a shared hosting.</p>