我撕裂我的頭髮試圖找出爲什麼當它在命令行中執行時,該工作可能可能無法正常工作。在完成渲染並使用ImageMagick將幀編譯爲GIF後,我向用戶發送POV-Ray動畫。我已經通過mutt sleep發送了一個小時的電子郵件,因此它允許編譯用戶動畫的時間。 (我把它改成了120秒,但是我不必等一個小時才能排除故障,在這方面我也讓動畫只有3幀,直到我找出問題所在。)Mutt的郵件不發送電子郵件了shell_exec
新的bash文件animation_done_bash.sh是每次用戶點擊我的站點上的動畫時創建的,而該動畫創建一個新的文件夾,用於存儲動畫的框架以及animation_done_bash.sh。爲了使PHP頁面前進到下一頁,bash文件在dev null中執行。我已經測試過,如果這是在命令行上的問題,它在那裏工作,所以我真的不知道是什麼問題。
下面是代碼和正在用了shell_exec執行輸出(I呼應了這一點,在我的PHP頁面,看看發生了什麼事)所產生:
$animation_done_email = "#!/usr/bin/bash \nsleep 120; mutt -s \"Animation Finished\" -a animation.gif -- ".$email." <email.txt;";
/*Creates new animation_done_bash each time user hits animate*/
$directory_bash = "./User_Files/Animation/".$location."/";
$filename_bash = 'animation_done_bash.sh';
$handler_bash = fopen($directory_bash.$filename_bash, "w");
fwrite($handler_bash, $animation_done_email);
fclose($handler_bash);
/*Need to change the permissions on bash file so it can execute*/
chmod($directory_bash."/animation_done_bash.sh", 0777);
$command_5 = 'cd /home/ouraccount/public_html/User_Files/Animation/'.$location.'/; bash animation_done_bash.sh > /dev/null 2>/dev/null &';
$shellOutput = shell_exec($command_5);
其中$ email是用戶的電子郵件$ location是存儲框架的文件夾。 email.txt存儲在同一個文件夾中。
輸出: CD /家庭/ ouraccount /的public_html/User_Files /動畫/ ani_51 /;的bash animation_done_bash.sh>的/ dev/null的2>的/ dev/null的&
任何指導將不勝感激。謝謝!
我想你會以錯誤的方式進行操作,只需在bash腳本中添加一條命令,以便在完成渲染後發送圖像。 – dtech 2013-04-27 12:45:17
這就是我想要做的。我無法弄清楚它在完成渲染時如何識別,所以我只是讓電子郵件發送睡眠。如果這不是正確的方法,我應該用什麼來代替mutt?我只是困惑,爲什麼它一切工作,當我從外殼執行它,但不是當它從PHP執行,即使我改變了權限。 – Dominick 2013-04-27 13:21:07
也許是因爲PHP暫停或用戶不正確或其他原因。太多的可能性,它只是不正確的PHP使用情況。我將在下面發佈一個示例代碼片段。這是一個XY問題:http://meta.stackexchange.com/questions/66377/what-is-the-xy-problem – dtech 2013-04-27 14:02:28