posix_getuid() returns non-zero if user is root or sudo, so you can warn user to use an appropriate permission if required.
<?php // check if the user is root or executed in sudo mode if (posix_getuid() != 0) { echo "Error: please run \"php {$argv[0]}\" in root or sudo\n\n"; exit; } ?>