Skip to content

Instantly share code, notes, and snippets.

@Kcko
Last active March 23, 2018 15:45
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save Kcko/0d4c0dba8157a20fce0eb992273414cd to your computer and use it in GitHub Desktop.
# To parse and execute a php script:
php file
# To check syntax on (i.e. lint) a PHP script:
php -l file
# To run PHP interactively:
php -a
# To run PHP code (Notes: Don't use <? ?> tags; escape double quotes with backslash):
php -r "code"
# To start a PHP built-in web server in the current directory:
php -S host:port
#!/usr/bin/env php
<?php
define('SNIPPETS_START', microtime(true));
if (defined('STDIN'))
{
echo 'PHP version .............: ' . phpversion() . PHP_EOL;
echo 'Script ..................: ' . basename(__FILE__) . PHP_EOL;
echo 'Directory ...............: ' . dirname(__FILE__) . PHP_EOL;
echo 'Start time ..............: ' . SNIPPETS_START . PHP_EOL;
echo 'Shell user ..............: ' . shell_exec('whoami') . PHP_EOL;
}
else
{
echo 'Console mode only!';
exit();
}
require __DIR__ . '/vendor/autoload.php';
// do cool php stuff here ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment