[英]postfix pipe to php script: how to fully log php errors/warning/notices?
在 Debian 10 的后綴中,我將收到的郵件傳送到 php 腳本 – 在 master.cf 中:
mail-pipe-script unix - nn - - pipe flags=DRhu user=mail-pipe-user argv=/usr/bin/php /var/www/html/admin/mail_pipe.php
一切正常,但任何 php 錯誤或警告都會返回到 postfix 並以截斷的形式記錄到/var/log/mail.log
- 我想在自己的日志文件中查看整個錯誤,或者至少在 mail.log 中沒有截斷。 我得到的最接近的是在 mail_pipe.php 的頂部:
#!/usr/bin/php
<?php
$x= exec('command 2>> /var/log/mail.log');
但是權限被拒絕,當然致命錯誤也不會被記錄下來。 我對降低日志權限有點緊張。 我也嘗試過其他日志目的地。 mail_pipe.php 擁有mail-pipe-user:www-data
BTW mail_pipe.php 使用標准輸入讀取 email:
$fd = fopen("php://stdin", "r");
有人可以建議更好的方法來完全記錄 php 腳本錯誤和警告等嗎?
謝謝!
AFAIK PHP 標准 I/O 流無法重新定義,只能關閉。 如果您有權訪問腳本源代碼,則可以通過set_error_handler
定義錯誤處理程序。 如果沒有,可以選擇用另一個腳本包裝您的腳本,這將控制目標 I/O 流。
<?php
// Call me wrapper.php
$pipes = [];
$real_process = proc_open(
'php ./wrapped.php',
[
["pipe", "r"],
["pipe", "w"],
["pipe", "w"]
],
$pipes
);
if( is_resource($real_process) ){
// Passing my stdin as-is
fwrite($pipes[0], stream_get_contents(STDIN));
fclose($pipes[0]);
$real_process_said = stream_get_contents($pipes[1]);
fclose($pipes[1]);
$real_process_whined = stream_get_contents($pipes[2]);
fclose($pipes[2]);
proc_close($real_process);
print "STDOUT was: $real_process_said";
print "STDERR was: $real_process_whined";
}
<?php
// Call me wrapped.php
print "The STDIN is: " . stream_get_contents(STDIN);
fwrite(STDERR, "i'm wrapped pleas halp!");
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.