PHP 想要接收 CLI PIPE 傳過來得值,可以使用 -R 加上 $argn 來拿取~
PHP 使用 $argn 接收 CLI Pipe 傳來的值
PHP $argn 可以參考此文件:PHP: Options - Manual
-R --process-code PHP code to execute for every input line. Added in PHP 5. There are two special variables available in this mode: $argn and $argi. $argn will contain the line PHP is processing at that moment, while $argi will contain the line number.
可以做下述測試
- $ echo "hello world" | php -R 'echo str_replace("world","test", $argn);'
想要即時查詢、呈現 https 過期的日期,可以寫成下述:
- $ vim ~/.bashrc # 加入此 function
function get_https_expire() { echo | openssl s_client -servername $1 -connect $1:443 2>/dev/null | openssl x509 -noout -dates | grep After | awk -F= '{print $2}' | php -R 'echo date("Y-m-d", strtotime($argn)) . "\n";' }
- $ source ~/.bashrc
- $ get_https_expire blog.longwin.com.tw # 下面此日期就是此網址 https 的過期日期
2018-06-28