title: Show Products Special From Date - Optimize Magento Script
body: <p>I am trying to list all products that have a special from date that is within the last 72 hours. The script works fine except over 400 products it times out.</p>
  
  <p>I think I am loading too many collections or not correctly utilizing the ones that are loaded so I really just need some optimization advice please.</p>
  
  <p>Here is the script:</p>
  
  <pre><code>&lt;?php
  
  
  set_time_limit(0);
  require_once 'app/Mage.php';
  Mage::app('default');
  
  try
  {
      $products = Mage::getModel('catalog/product')-&gt;getCollection()
          -&gt;setStoreId(1);
      $products-&gt;addAttributeToFilter('status', 1);
      $products-&gt;addAttributeToFilter('visibility', 4);
      $products-&gt;addAttributeToSelect('*');
      $prodIds=$products-&gt;getAllIds();
      $product_count = 0;
      $products_changed = 0;
  
      //$product = Mage::getModel('catalog/product');
  
      echo "Price Changes Last 72 Hours&lt;br&gt;&lt;br&gt;";
  
      foreach($prodIds as $productId) 
      {
          $product_count++;
          //$products-&gt;load($productId);
  
          // load product data
          $product = Mage::getModel('catalog/product')-&gt;load($productId);
  
          $special_price = round($product-&gt;getSpecialprice(),2);
          $human_readable_date = $product-&gt;getSpecialFromDate();
          $sku = $product-&gt;getSku();
          $specialPriceFromDate = strtotime($human_readable_date);
          $time_now = microtime(true);
          $product_link = "http://www.mydomain.com.au/".$product-&gt;getUrlPath(); 
          $date_array = explode( ' ', $human_readable_date);
          $short_date = $date_array[0];
  
          if (($time_now - $specialPriceFromDate) &lt; 259200)
          {
              $products_changed++; 
              echo "SKU: " . '&lt;a href=' . $product_link . '&gt;' . $sku . '&lt;/a&gt;' . "  Date Changed: " . $short_date . " New Price $" . $special_price . "&lt;br&gt;";
          }
          //if ($product_count == 400) exit;  
      }
  }
  
  catch(Exception $e){
      $headers = 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; 
      error_log($e-&gt;getMessage(), 1, 'me@mydomain.com.au', $headers);
      die($e-&gt;getMessage());
  }
  
  
  ?&gt;
  </code></pre>