private function _call()
    {

        // Time this
        $t = new Timer('CUPS extension');

        // Deal with calling it
        try {
            $result = $this->_CallExt->exec('lpstat', '-p -o -l');
        } catch (Exception $e) {
            // messed up somehow
            Errors::add('CUPS Extension', $e->getMessage());
            $this->_res = false;

            // Don't bother going any further
            return false;
        }

        // Split it into lines
        $lines = explode("\n", $result);

        // Hold temporarily values here
        $printers = [];
        $queue = [];
        $begin_queue_list = false;

        // Go through it line by line
        for ($i = 0, $num = count($lines); $i < $num; ++$i) {

            // So regexes don't break on endlines
            $lines[$i] = trim($lines[$i]);

            // If there are no entries, don't waste time and end here
            if ($lines[$i] == 'no entries') {
                break;
            } elseif (preg_match('/^printer (.+) is idle\. (.+)$/', $lines[$i], $printers_match) == 1) {
                $printers[] = array(
                    'name' => str_replace('_', ' ', $printers_match[1]),
                    'status' => $printers_match[2],
                );
            }

            // A printer entry
            elseif (preg_match('/^(.+)+ is (ready|ready and printing|not ready)$/', $lines[$i], $printers_match) == 1) {
                $printers[] = array(
                    'name' => str_replace('_', ' ', $printers_match[1]),
                    'status' => $printers_match[2],
                );
            }

            // The beginning of the queue list
            elseif (preg_match('/^Rank\s+Owner\s+Job\s+File\(s\)\s+Total Size$/', $lines[$i])) {
                $begin_queue_list = true;
            }

            // A job in the queue
            elseif ($begin_queue_list && preg_match('/^([a-z0-9]+)\s+(\S+)\s+(\d+)\s+(.+)\s+(\d+) bytes$/', $lines[$i], $queue_match)) {
                $queue[] = array(
                    'rank' => $queue_match[1],
                    'owner' => $queue_match[2],
                    'job' => $queue_match[3],
                    'files' => $queue_match[4],
                    'size' => Common::byteConvert($queue_match[5]),
                );
            }
        }

        // Save result lset
        $this->_res = array(
            'printers' => $printers,
            'queue' => $queue,
        );

        // Apparent success
        return true;
    }
private function _call()
    {

        // Time this
        $t = new Timer('CUPS extension');

        // Deal with calling it
        try {
            $result = $this->_CallExt->exec('lpstat', '-p -o -l');
        } catch (Exception $e) {
            // messed up somehow
            Errors::add('CUPS Extension', $e->getMessage());
            $this->_res = false;

            // Don't bother going any further
            return false;
        }

        // Split it into lines
        $lines = explode("\n", $result);

        // Hold temporarily values here
        $printers = [];
        $queue = [];
        $begin_queue_list = false;

        // Go through it line by line
        for ($i = 0, $num = count($lines); $i < $num; ++$i) {

            // So regexes don't break on endlines
            $lines[$i] = trim($lines[$i]);

            // If there are no entries, don't waste time and end here
            if ($lines[$i] == 'no entries') {
                break;
            } elseif (preg_match('/^printer (.+) is idle\. (.+)$/', $lines[$i], $printers_match) == 1) {
                $printers[] = array(
                    'name' => str_replace('_', ' ', $printers_match[1]),
                    'status' => $printers_match[2],
                );
            }

            // A printer entry
            elseif (preg_match('/^(.+)+ is (ready|ready and printing|not ready)$/', $lines[$i], $printers_match) == 1) {
                $printers[] = array(
                    'name' => str_replace('_', ' ', $printers_match[1]),
                    'status' => $printers_match[2],
                );
            }

            // The beginning of the queue list
            elseif (preg_match('/^Rank\s+Owner\s+Job\s+File\(s\)\s+Total Size$/', $lines[$i])) {
                $begin_queue_list = true;
            }

            // A job in the queue
            elseif ($begin_queue_list && preg_match('/^([a-z0-9]+)\s+(\S+)\s+(\d+)\s+(.+)\s+(\d+) bytes$/', $lines[$i], $queue_match)) {
                $queue[] = array(
                    'rank' => $queue_match[1],
                    'owner' => $queue_match[2],
                    'job' => $queue_match[3],
                    'files' => $queue_match[4],
                    'size' => Common::byteConvert($queue_match[5]),
                );
            }
        }

        // Save result lset
        $this->_res = array(
            'printers' => $printers,
            'queue' => $queue,
        );

        // Apparent success
        return true;
    }
private function _call ( ) { // Time this $ t = new Timer ( 'CUPS extension' ) ; // Deal with calling it try { $ result = $ this -> _CallExt -> exec ( 'lpstat' , '-p -o -l' ) ; } catch ( Exception $ e ) { // messed up somehow Errors :: add ( 'CUPS Extension' , $ e -> getMessage ( ) ) ; $ this -> _res = false ; // Don't bother going any further return false ; } // Split it into lines $ lines = explode ( "\n" , $ result ) ; // Hold temporarily values here $ printers = [ ] ; $ queue = [ ] ; $ begin_queue_list = false ; // Go through it line by line for ( $ i = 0 , $ num = count ( $ lines ) ; $ i < $ num ; ++ $ i ) { // So regexes don't break on endlines $ lines [ $ i ] = trim ( $ lines [ $ i ] ) ; // If there are no entries, don't waste time and end here if ( $ lines [ $ i ] == 'no entries' ) { break ; } elseif ( preg_match ( '/^printer (.+) is idle\. (.+)$/' , $ lines [ $ i ] , $ printers_match ) == 1 ) { $ printers [ ] = array ( 'name' => str_replace ( '_' , ' ' , $ printers_match [ 1 ] ) , 'status' => $ printers_match [ 2 ] , ) ; } // A printer entry elseif ( preg_match ( '/^(.+)+ is (ready|ready and printing|not ready)$/' , $ lines [ $ i ] , $ printers_match ) == 1 ) { $ printers [ ] = array ( 'name' => str_replace ( '_' , ' ' , $ printers_match [ 1 ] ) , 'status' => $ printers_match [ 2 ] , ) ; } // The beginning of the queue list elseif ( preg_match ( '/^Rank\s+Owner\s+Job\s+File\(s\)\s+Total Size$/' , $ lines [ $ i ] ) ) { $ begin_queue_list = true ; } // A job in the queue elseif ( $ begin_queue_list && preg_match ( '/^([a-z0-9]+)\s+(\S+)\s+(\d+)\s+(.+)\s+(\d+) bytes$/' , $ lines [ $ i ] , $ queue_match ) ) { $ queue [ ] = array ( 'rank' => $ queue_match [ 1 ] , 'owner' => $ queue_match [ 2 ] , 'job' => $ queue_match [ 3 ] , 'files' => $ queue_match [ 4 ] , 'size' => Common :: byteConvert ( $ queue_match [ 5 ] ) , ) ; } } // Save result lset $ this -> _res = array ( 'printers' => $ printers , 'queue' => $ queue , ) ; // Apparent success return true ; }
call lpq and parse it
call lpq and parse it