把 php 脚本当成 shell 脚本来用
10 June 2018
#!/usr/bin/env php -q
<?php

echo 'hello world' . PHP_EOL;

// https://stackoverflow.com/questions/2063322/what-does-the-q-php-command-line-option-do
// The -q flag suppresses HTTP header output. As long as your script itself does not send anything to stdout, -q will prevent cron from sending you an email every time the script runs. For example, print and echo send to stdout. Avoid using these functions if you want to prevent cron from sending you email.

重定向日志

fclose(STDOUT);

$handle = fopen("./test.log", "a");
echo 'ok' . PHP_EOL;
fclose($handle);

// cat test.log
// ok