-1
터미널의 bash 스크립트에서 실행하는 PHP 스크립트를 작성했습니다. 나는 PHP5 php-cli와 php-pear를 설치했다. PHP 스크립트는 브라우저를 사용하여 아파치 서버에서 원활하게 실행되지만 터미널에서 실행할 때는 아무런 효과가 없습니다. 또한 모든 사람에게 읽기 및 쓰기 권한으로 실행 가능하도록 만듭니다. 5 분마다 cron 작업을 실행할 bash 스크립트를 작성합니다.PHP는 터미널에서 php-cli로 실행하지 않고 apache 서버에서 실행합니다.
#!/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*/
?>
어떻게 불러 옵니까? 오류가 있습니까? –
특정 방식으로 실행되지 않습니까? –
터미널에서 직접 실행하면 오류가 없습니다. 나는 단지'php -f/path/to/file/process.php'를 사용한다. 텍스트 파일은 그 후에 만들어야하지만 터미널에서 실행되는 경우 텍스트 파일을 생성하지 않습니다. 그러나 웹 브라우저 http : //localhost/process.php에서 실행할 때 파일을 생성했기 때문에 브라우저를 열지 않아도 자동으로 실행되어야합니다. 그래서 터미널에서 실행하려고합니다. : –