質問するログイン新規登録

質問編集履歴

3

追記

2017/10/10 05:21

投稿

mugen
mugen

スコア13

title CHANGED
File without changes
body CHANGED
@@ -63,4 +63,32 @@
63
63
  $return_varの返り値は0なので正常終了しているということではないのでしょうか?
64
64
 
65
65
  なぜexecが動かないのか見当もつかないので解決の糸口でもつかめたらと思っています。
66
- よろしくお願い致します。
66
+ よろしくお願い致します。
67
+
68
+
69
+ ###追記
70
+ ①同じ条件でロリポップのサーバーで試してみたところ、問題なく動きました。
71
+
72
+ なのでそもそもexecが使えないのか?と思い
73
+ ```
74
+ echo exec('ls -l /virtual/exectest/');
75
+ ```
76
+ を試すも問題なく表示されました。
77
+
78
+ ②試したことで出たStatus: 404が気になり、require_onceで
79
+ execで呼び出すphpと同じパスを入れてみました。
80
+ ```
81
+ require_once ('/virtual/exectest/exectest.php');
82
+ exec('nohup php /virtual/exectest/exectest.php > /dev/null &');
83
+
84
+ ```
85
+
86
+ exectest.phpはメールを送るものだけにしました。
87
+ ```
88
+ mail($to, $subject, $message, $headers);
89
+ ```
90
+ するとなぜかメールが2通届くようになりました。
91
+ これは、require_onceとexecで2回呼び出されているからなのでしょうか?
92
+ require_onceを消すとメールは1通も届きません。
93
+
94
+ なにか気が付いた点があれば教えてください。

2

加筆修正

2017/10/10 05:21

投稿

mugen
mugen

スコア13

title CHANGED
File without changes
body CHANGED
@@ -3,42 +3,64 @@
3
3
  もともとシステムにexecで外部スクリプトを実行するものが組み込まれていて、
4
4
  移行前のサーバーでは問題なく動いていました。
5
5
 
6
- ところが移行先のサーバーではexecが動いておらず、サーバー側に確認すると
6
+ ところが移行先のサーバーではexecが動いていませんでした。
7
7
 
8
- shtml以外の拡張子SSIを実行させ場合、「.htaccess」ファイルを使用して設定を変更する必要があります。
8
+ exec外部スクリプトを実行部分phpファイルの中に以下の記述があります。
9
+ ```
10
+ exec('php /virtual/exectest/exectest.php > /dev/null &');
11
+ ```
9
12
 
10
- 回答でした。
13
+ これが動かなかったので以下で試てみました。
14
+ ```
15
+ chmod("/virtual/exectest/log", 0755);
16
+ exec('php /virtual/exectest/exectest.php > /dev/null &', $output, $return_var);
17
+ var_dump($output,$return_var);
18
+ ```
11
19
 
12
- execが動かなかったのはphpファイルのみでSSIを実行させようとしたからのでしょか?
20
+ array(0) { } int(0)と帰てきましがexectest.php実行ささそです。
21
+ chmodの返り値はtrueだったので成功していると思います。
13
22
 
14
-
15
- また、「.htaccess」で以下記述をしたのですが、phpのコードが出きてしまいました
23
+ 実行するexectest.php方にはログファイル作る処理をしていま
16
24
  ```
17
- <Files "itemsEditor.php">
18
- Options +Includes
19
- Addtype "text/html; charset=utf-8" .html .shtml .php .inc
25
+ error_log('message', 3, '/virtual/exectest/test.log');
20
- AddOutputFilter INCLUDES .html .shtml .php .inc
21
- AddHandler server-parsed .html .shtml .php .inc
22
- </Files>
23
26
  ```
27
+ 直接exectest.phpにアクセスするとログファイルが作成されるのですが、
28
+ execの方では作成されませんでした。
24
29
 
25
- 記述順でphpのコードが出てきてしまうことがあるという記事を見つけたので以下のように変更したところphpファイルが実行されず、ダウンロードされてしまうようになりました。
26
- ```
27
- <Files "itemsEditor.php">
28
- Options +Includes
29
- Addtype "text/html; charset=utf-8" .html .shtml .php .inc
30
- AddOutputFilter INCLUDES .html .shtml .php .inc
31
- AddHandler server-parsed .html .shtml .php .inc
32
30
 
33
- AddType "application/x-httpd-php; charset=utf-8" .php .inc
31
+ ###試したこと
34
- AddType "application/x-httpd-php-source; charset=utf-8" .phps
35
- </Files>
32
+ 上記コードでダメだったので以下のコードを試してみました。
36
33
  ```
34
+ exec('nohup php /virtual/exectest/exectest.php 2>&1', $output, $return_var);
35
+ var_dump($output);
36
+ var_dump($return_var);
37
+ ```
38
+ 返り値は以下の通りです。
39
+ ```
40
+ array(13) {
41
+ [0]=> string(23) "Content-type: text/html"
42
+ [1]=> string(0) ""
37
- 変更後の現象はMIMEタイプが違っているからダウンロードされてしまうと思うのですが、
43
+ [2]=> string(10) "array(4) {"
38
- phpのMIMEタイプが間違っているのでしょうか?
44
+ [3]=> string(7) "
45
+ [0]=>"
46
+ [4]=> string(26) " string(11) "Status: 404""
47
+ [5]=> string(7) "
48
+ [1]=>"
49
+ [6]=> string(38) " string(23) "Content-type: text/html""
50
+ [7]=> string(7) "
51
+ [2]=>"
52
+ [8]=> string(14) " string(0) """
53
+ [9]=> string(7) "
54
+ [3]=>"
55
+ [10]=> string(39) " string(24) "No input file specified.""
56
+ [11]=> string(1) "}"
57
+ [12]=> string(8) "int(255)" }
58
+ int(0)
59
+ ```
39
60
 
61
+ ファイルが見つからないエラーだと思うのですが
62
+ 同階層に入れていて見つからないというのも謎で、
63
+ $return_varの返り値は0なので正常終了しているということではないのでしょうか?
40
64
 
41
- execで外部スクリプトを実行する部分はphpファイル中に以下記述があります。
65
+ なぜexecが動かないか見当もつかないで解決の糸口でもつかめたらと思っています。
42
- ```
66
+ よろしくお願い致します。
43
- exec('php /virtual/IPアドレス/home/html_test/admin/exectest.php > /dev/null &');
44
- ```

1

追記

2017/10/02 10:05

投稿

mugen
mugen

スコア13

title CHANGED
File without changes
body CHANGED
@@ -35,4 +35,10 @@
35
35
  </Files>
36
36
  ```
37
37
  変更後の現象はMIMEタイプが違っているからダウンロードされてしまうと思うのですが、
38
- phpのMIMEタイプが間違っているのでしょうか?
38
+ phpのMIMEタイプが間違っているのでしょうか?
39
+
40
+
41
+ execで外部スクリプトを実行する部分はphpファイルの中に以下の記述があります。
42
+ ```
43
+ exec('php /virtual/IPアドレス/home/html_test/admin/exectest.php > /dev/null &');
44
+ ```