<?php

require_once dirname(__FILE__) . '/../../bootstrap.php';
Core::setUser(UserAccount::get(UserAccount::ID_SYSTEM_ACCOUNT));
$productIds = Dao::getResultsNative('select distinct id from product where active = 1', array(), PDO::FETCH_ASSOC);
foreach ($productIds as $row) {
    try {
        $output = '';
        $cmd = 'php ' . dirname(__FILE__) . '/pricematch.php ' . $row['id'];
        $output = ExecWaitTimeout($cmd, 10);
        // 	exec($cmd, $output);
        echo print_r($output, true) . "\n";
    } catch (Exception $e) {
        echo $e->getMessage() . "\n";
    }
}
/**
 * Execute a command and kill it if the timeout limit fired to prevent long php execution
 * 
 * @see http://stackoverflow.com/questions/2603912/php-set-timeout-for-script-with-system-call-set-time-limit-not-working
 * 
 * @param string $cmd Command to exec (you should use 2>&1 at the end to pipe all output)
 * @param integer $timeout
 * @return string Returns command output 
 */
function ExecWaitTimeout($cmd, $timeout = 5)
{
    echo $cmd . "\n";
    $descriptorspec = array(0 => array("pipe", "r"), 1 => array("pipe", "w"), 2 => array("pipe", "w"));
    $pipes = array();
    $timeout += time();
Example #2
0
Core::setUser(UserAccount::get(UserAccount::ID_SYSTEM_ACCOUNT));
echo "Begin at MELB TIME: " . UDate::now(UDate::TIME_ZONE_MELB) . "\n";
if (isset($argv) && isset($argv[1]) && Product::get($argv[1]) instanceof Product) {
    $productIds = Dao::getResultsNative('select distinct p.id from product p where p.id = ?', array($argv[1]), PDO::FETCH_ASSOC);
} else {
    $productIds = Dao::getResultsNative('select distinct p.id from product p inner join productpricematchrule r on (r.productId = p.id and r.active = 1) where p.active = 1 order by p.id', array(), PDO::FETCH_ASSOC);
}
$rows = count($productIds);
echo "--- Got ({$rows}) products having price matching rules !";
foreach ($productIds as $row) {
    try {
        $output = '';
        $timeout = 60;
        // in seconds
        $cmd = 'php ' . dirname(__FILE__) . '/pricematch.php ' . $row['id'];
        $output = ExecWaitTimeout($cmd, $timeout);
        // 	exec($cmd, $output);
        echo print_r($output, true) . "\n";
    } catch (Exception $e) {
        echo $e->getMessage() . "\n";
    }
}
echo "End at MELB TIME: " . UDate::now(UDate::TIME_ZONE_MELB) . "\n";
/**
 * Execute a command and kill it if the timeout limit fired to prevent long php execution
 * 
 * @see http://stackoverflow.com/questions/2603912/php-set-timeout-for-script-with-system-call-set-time-limit-not-working
 * 
 * @param string $cmd Command to exec (you should use 2>&1 at the end to pipe all output)
 * @param integer $timeout
 * @return string Returns command output