title: How to get linux console $COLUMNS and $ROWS from PHP cli?
body: <p>I'm currently creating a new neat CLI library for PHP, and i'd like to figure out the width/height of the console it's running in. </p>
  
  <p>I've tried many things like digging through $_ENV, exec("echo $COLUMNS"), etc, but no result, while if i type echo $COLUMNS or $ROWS in bash commandline, it neatly displays the value.</p>
  
  <p>What do i need to do to access this value from PHP?</p>
  
  <p>I'm using .sh scripts like this:</p>
  
  <pre><code>#!/usr/bin/php -q
  &lt;?php
  
  require_once('lib.commandline.php');
  
  
  class HelloWorld extends CommandLineApp {
  
    public function main($args) {
  
         echo('O, Hai.');
  
      }
  
  }
  </code></pre>
  
  <p><strong>Update</strong>
  Final solution:</p>
  
  <pre><code>public function getScreenSize() { 
        preg_match_all("/rows.([0-9]+);.columns.([0-9]+);/", strtolower(exec('stty -a |grep columns')), $output);
        if(sizeof($output) == 3) {
          $this-&gt;settings['screen']['width'] = $output[1][0];
          $this-&gt;settings['screen']['height'] = $output[2][0];
        }
      }
  </code></pre>