[英]PHP wont run in terminal with php-cli but runs in apache server
I wrote a php script that is intended to run from a bash script in terminal.我编写了一个 php 脚本,旨在从终端中的 bash 脚本运行。 I installed PHP5 php-cli and php-pear.我安装了 PHP5 php-cli 和 php-pear。 THe PHP Scripts runs smoothly in apache server using a browser but it does nothing when run from terminal. PHP 脚本使用浏览器在 apache 服务器中流畅运行,但从终端运行时它什么也不做。 I also make it to be executable with read and write permission to all.我还使它具有对所有人的读写权限的可执行文件。 I will put that bash script to run in cron jobs every 5 minutes.我会让那个 bash 脚本每 5 分钟在 cron 作业中运行一次。
#!/usr/bin/php5 -q
<?php
$file="/var/www/floods/php/indx.txt";
$indx=file_get_contents($file);
$con = mysql_connect("localhost","user","password");
if(!$con){die('Could not connect: ' . mysql_error());}
mysql_select_db("smsgw",$con);
$acc = mysql_query("SELECT * FROM accounts");
while($fld = mysql_fetch_array($acc)){
$index[]=$fld['id'];
$num_reg[]=$fld['num'];
$loc[]=$fld['location'];
}
if(isset($index)){
$inbox = mysql_query("SELECT * FROM inbox");
while($fields=mysql_fetch_array($inbox)){
$id[]=$fields['id'];
$num_inbox[]=$fields['number'];
$smsdate[]=$fields['smsdate'];
$text[]=$fields['text'];
}
$last_indx=count($id);
$last_num=count($index);
for($i=0;$i<$last_num;$i++){
for($j=(int)$indx;$j<$last_indx;$j++){
if(strcmp($num_inbox[$j],$num_reg[$i])==0){
$file_save= $num_reg[$i] . ".txt";
file_put_contents($file_save,$text[$j]);
}
}
}
}/*End*/
?>
Thanks for those who comments and help.感谢那些评论和帮助的人。 Finally solved the Problem.终于解决了问题。 I should specified the exact path where to save the text files.我应该指定保存文本文件的确切路径。 $file_save= $num_reg[$i] . ".txt";
should be like this $file_save="/path/where/to/save". $num_reg[$i] . ".txt";
应该像这样$file_save="/path/where/to/save". $num_reg[$i] . ".txt";
$file_save="/path/where/to/save". $num_reg[$i] . ".txt";
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.