title: Writing files to webroot in a loop, "Fatal error: ReflectionClass::getProperties()"
body: <p>I am calling this function from my browser through a controller:    </p>
  
  <pre><code>function writePages($startPage)
  {
      for ($page=$startPage;$page&lt;90;$page++)
      {
          $content=file_get_contents('http://www.websiteIamUsing.com/'.$page);
          $handle=fopen('mytxtfile'.$page.'.txt','w');
          fwrite($handle,$content);
          fclose($handle);
      }
  }
  </code></pre>
  
  <p>For some reason, this will write the first 20-something, or sometimes 50-something files, but then it will stop and give me this error:</p>
  
  <pre><code>Warning: get_class() expects parameter 1 to be object, resource given in 
  /Applications/MAMP/htdocs/mysite/lib/Cake/Utility/Debugger.php on line 579
  
  Warning: get_object_vars() expects parameter 1 to be object, resource given in 
  /Applications/MAMP/htdocs/mysite/lib/Cake/Utility/Debugger.php on line 585
  
  Warning: Invalid argument supplied for foreach() in 
  /Applications/MAMP/htdocs/mysite/lib/Cake/Utility/Debugger.php on line 586
  
  Warning: ReflectionObject::__construct() expects parameter 1 to be object, resource 
  given in /Applications/MAMP/mysite/alexmohamed/lib/Cake/Utility/Debugger.php 
  on line 592
  
  Fatal error: ReflectionClass::getProperties() 
  [&lt;a href='http://php.net/reflectionclass.getproperties'&gt;reflectionclass.getproperties&lt;/a&gt;]: 
  Internal error: Failed to retrieve the reflection object in 
  /Applications/MAMP/htdocs/mysite/lib/Cake/Utility/Debugger.php on line 594
  </code></pre>
  
  <p>Can anyone explain to me what is going on here? Since it begins to work, I suspect maybe CakePHP doesn't let you run a script for longer than a certain amount of time or something? Is there a way around this? This is a controller action that only I will use...it won't be used by the users of the site so it can take a long time (this one should take about a minute).</p>
  
  <p><strong>Edit</strong>: If you look at the errors, it appears to be trying to debug something, but since cakePHP is passing a "resource" rather than an "object" to the debugger, it won't tell me the real error. Why would this be an unreliable action...sometimes it completes until the end, sometimes it stops after ~20 files, sometimes after ~50...</p>