Skip to content

Instantly share code, notes, and snippets.

@pavlepredic
Created March 28, 2013 14:17
Show Gist options
  • Save pavlepredic/5263451 to your computer and use it in GitHub Desktop.
Save pavlepredic/5263451 to your computer and use it in GitHub Desktop.
Interactive PHP shell. In Windows, running php in interactive mode is pretty quirky. This script attempts to solve this problem. It allows entering entire function definitions and classes. You may enter code on multiple lines. Nothing will be evaluated until you enter a semicolon. Save this to a file and run it from console. Hit CTRL+C to exit.
<?php
$fh = fopen('php://stdin', 'r');
$cmd = '';
$bcLvl = 0;
while (true)
{
$line = rtrim(fgets($fh));
$bcLvl += substr_count($line, '{') - substr_count($line, '}');
$cmd.= $line;
if ($bcLvl > 0 or substr($cmd, -1) !== ';')
continue;
eval($cmd);
$cmd = '';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment