title: Ajax request cause following : Failed to load resource: the server responded with a status of 500 (Internal Server Error)
body: <p>I know there are a lot of related article on this and i had tried most of the suggestions from other sharing. Here is partial listing of my code </p>
  
  <pre><code>$(document).ready(function() {
      $("#cron").click(function(event) { 
          $('.update-body').html('&lt;br /&gt;Performing updates...&lt;br /&gt;')
          event.preventDefault();
          event.stopPropagation();
          var request = $.ajax({
             url: 'http://xx.xx.xx.xx/update/longprocessing',
             type: "GET",
             contentType: "application/json",
             beforeSend: function (xhr) {
             var token = $('meta[name="csrf_token"]').attr('content');
  
             if (token) {
               return xhr.setRequestHeader('X-CSRF-TOKEN', token);
             }
         },
         dataType: "json"
      });
  
      request.done(function(status) {
         var msg = "";
         if(status.msg == '1')
         {
             msg = '&lt;div class="alert alert-success"&gt;Successfully updated.&lt;/div&gt;';
         }
         else if(status.msg == '2')
         {
             msg = '&lt;div class="alert alert-info"&gt;No updates&lt;/div&gt;';
         }
         $('.update-body').html(msg);
     });
  
     request.fail(function(jqXHR, textStatus) {
       var acc = []
       $.each(jqXHR, function(index, value) {
         acc.push(index + ': ' + value);
     });
     $('.update-body').html('&lt;div class="alert alert-danger"&gt;' JSON.stringify(acc) + '&lt;/div&gt;');
     });
   });
  });
  </code></pre>
  
  <p>Processing.php is expected to takes an average of 40 minute to complete. Here is the problem, the code runs well and a success message is returned when i run XAMPP on windows 10 platform. </p>
  
  <p>When i move the code to Linux under XAMPP, processing.php shows no error and runs perfectly fine (so nothing wrong with the php code) but when i monitor the network performance, when waiting (TTFB) time to first byte hit 15 minutes, the following error message : Failed to load resource: the server responded with a status of 500 (Internal Server Error) is generated somewhere in the jquery ajax code. I am using jquery1.12.3.</p>
  
  <p>Any help is greatly appreciated.</p>
  
  <p>I also realize sometimes, my php function get called the first time and after 6 minute, it is called a second time followed by 503 service not available. It does not happen in xampp under windows but happens in linux. I am using laravel 5.2 framework as follows:</p>
  
  <pre><code>Route::get('/update/longprocessing', ['as' =&gt; 'UpdateProcess', 'uses' =&gt; 'Project\ProcessJobs@UpdateProcess']);
  </code></pre>
  
  <p>In my ProcessJobs.php, code as follows:</p>
  
  <pre><code>public function UpdateProcess () {
            Log::debug("Update Process started");
             $counter =0;
            //get path to linux folder
             ...
            //loop through folder to get all 35000 csvfiles
             foreach (xxx as xxx) {  
            //for each file, read content, process and write to a single common csv files.
                $counter++;
                Log::debug("counter value : " . $counter);
             }
  
           return response()-&gt;json(['msg'=&gt;'1']);
  }
  </code></pre>
  
  <p>Log file shows the following:</p>
  
  <pre><code>Update Process started
  counter value : 1
  counter value : 2
  counter value : 3
  ...
  ...
  counter value : 10000
  Update Process started    &lt;--- this is the second time it is called
  counter value : 10001     &lt;--- counter still continue from previous.
  counter value : 10002     &lt;--- log file stop here and server return 503 service unavailable error.
  </code></pre>