• Edit
  • Delete

php cli shell script cheatsheet

Shebang

#!/usr/bin/php
<?php

Arguments

$_SERVER['argv'][0] // = scriptname (myscript.php)

$_SERVER['argv'][1] // = first cmd argument "foo" (myscript.php foo)

Get Environment Variable

$certbotDomain = getenv('CERTBOT_DOMAIN');

Write to stderr

fwrite(STDERR, “hello, world\n”);

Exit code

exit(1);

Execute a shell command and return the output

$output = shell_exec('uname -r');

Disable xdebug html output

ini_set('html_errors', false);