Login   Register  
PHP Classes
elePHPant
Icontem

File: throttle_heavy_program.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Manuel Lemos  >  System monitor and Throttle  >  throttle_heavy_program.php  >  Download  
File: throttle_heavy_program.php
Role: Example script
Content type: text/plain
Description: Example of how to throttle the execution of an heavy program
Class: System monitor and Throttle
Monitor system usage and throttle heavy programs
Author: By
Last change:
Date: 2010-10-24 23:20
Size: 861 bytes
 

Contents

Class file image Download
<?php
/*
 * throttle_heavy_program.php
 *
 * @(#) $Id: throttle_heavy_program.php,v 1.1 2010/10/25 06:04:01 mlemos Exp $
 *
 */

    
require('system_monitor.php');
    
    function 
stopped($arguments)
    {
        echo 
'Process stopped due to cause '.$arguments['Cause'],"\n";
        return 
true;
    }

    function 
continued($arguments)
    {
        echo 
'Process continued',"\n";
        return 
true;
    }

    
$monitor = new system_monitor_class;
    
$monitor->cpu_load_limit 2;
    
$monitor->temporary_directory '/tmp/';
    
$command 'php -q heavy_program.php';
    
$parameters = array(
        
'Command' => $command,
        
'PollInterval'=>5,
        
'OnStop' => 'stopped',
        
'OnContinue' => 'continued',
        
'CaptureOutput'=>'array',
    );
    if(!
$monitor->ThrottleExecute($parameters))
    {
        echo 
'Could not execute the heavy process: '.$monitor->error."\n";
        exit;
    }
    
var_dump($parameters['Status'], $parameters['Output']);
?>