[PHP-users 25563] Re: バックグラウンド処理で自プログラムがコールされてしまう。

mochizuki mochizuki @ adcoop.co.jp
2005年 5月 10日 (火) 18:40:51 JST


望月です。

中途半端な投稿してすみませんでした。

テスト用に syslog.php を用意。
/var/log/messages に出力してみました。

[root @ xxxxxx tools]# vi syslog.php

syslog.php の内容

<?php
$access = date("Y/m/d H:i:s");
syslog(LOG_WARNING,"PHP-TEST: $access");
?>

実行可能に。(webmaster が アパッチのuser:group)の場合
[root @ xxxxxx tools]# chown webmaster:webmaster syslog.php
[root @ xxxxxx tools]# chmod 770 syslog.php

rootでテスト
テスト1
[root @ xxxxxx tools]# /usr/local/bin/php  -f syslog.php
テスト1結果
[root @ xxxxxx tools]# tail -f /var/log/messages
May 10 18:14:42 xxxxxx php: PHP-TEST: 2005/05/10 18:14:42

テスト2
[root @ xxxxxx tools]# /usr/local/bin/php  -f syslog.php > /dev/null
てすと2結果
[root @ xxxxxx tools]# tail -f /var/log/messages
May 10 18:14:42 xxxxxx php: PHP-TEST: 2005/05/10 18:14:42
May 10 18:16:04 xxxxxx php: PHP-TEST: 2005/05/10 18:16:04

テスト3
[root @ xxxxxx tools]# /usr/local/bin/php  -f syslog.php > /dev/null &
[13] 1650
テスト3結果
[root @ xxxxxx tools]# tail -f /var/log/messages
May 10 18:14:42 xxxxxx php: PHP-TEST: 2005/05/10 18:14:42
May 10 18:16:04 xxxxxx php: PHP-TEST: 2005/05/10 18:16:04
May 10 18:17:31 xxxxxx php: PHP-TEST: 2005/05/10 18:17:31

webmasterでテスト
[webmaster @ xxxxxx tools]# /usr/local/bin/php  -f syslog.php
結果
[root @ xxxxxx tools]# tail -f /var/log/messages
May 10 18:14:42 xxxxxx php: PHP-TEST: 2005/05/10 18:14:42
May 10 18:16:04 xxxxxx php: PHP-TEST: 2005/05/10 18:16:04
May 10 18:17:31 xxxxxx php: PHP-TEST: 2005/05/10 18:17:31
May 10 18:24:21 xxxxxx su(pam_unix)[1652]: session opened for user
webmaster by hogehoge(uid=0)
May 10 18:29:27 xxxxxx php: PHP-TEST: 2005/05/10 18:29:27

君山さんのsub.phpがウェブサーバから実行可能で
ログへの書き込み権限があれば、動くと思います。




PHP-users メーリングリストの案内