2013-04-02 1 views
1

exec 및 shell_exec에 문제가 있습니다. 여기에있는 모든 게시물을 살펴 보았으므로 문제를 찾을 수 없습니다. 내가 사용하고있는 코드 :exec 및 shell_exec이 PHP에서 작동하지 않습니다.

chdir('/'); 
$handle = shell_exec("/usr/bin/php /home/donor/public_html/batch/testlaunch.php 2>&1"); 
echo $handle .":". gettype($handle) . "\n"; 
$read = fread($handle, 2096); 
echo $read; 

화면은 다음과 같습니다

... 
X-Powered-By: PHP/5.3.21 Content-type: text/html (repeated about 100 times) 
X-Powered-By: PHP/5.3.21 Content-type: text/html 
PHP Warning: shell_exec() [function.shell-exec]: Unable to execute '/usr/bin/php /home/donor/public_html/batch/testlaunch.php 2>&1' in /home/donor/public_html/batch/test.php on line 4 X-Powered-By: PHP/5.3.21 Content-type: text/html 
Warning: shell_exec() [function.shell-exec]: Unable to execute '/usr/bin/php /home/donor/public_html/batch/testlaunch.php 2>&1' in /home/donor/public_html/batch/test.php on line 4 
:boolean PHP Warning: fread() expects parameter 1 to be resource, boolean given in /home/donor/public_html/batch/test.php on line 6 
Warning: fread() expects parameter 1 to be resource, boolean given in /home/donor/public_html/batch/test.php on line 6 
:string PHP Warning: fread() expects parameter 1 to be resource, string given in /home/donor/public_html/batch/test.php on line 6 (repeated another 100ish times) 

PHP의 안전 모드가 해제됩니다. .../batch /와/usr/bin/php에있는 폴더의 권한은 모두 755로 설정됩니다. 모든 파일의 사용자는 php (php file user는 root)를 제외하고 모두 동일합니다. php.ini 파일에서 아무 것도 비활성화됩니다. CLI에서 제대로 작동합니다. whoamils과 같은 간단한 명령이 정상적으로 작동합니다. 난 내가 뭔가를

EDIT를 놓친 거지 같은 느낌 : 무엇 cpattersonv1 말했다 노력하고 있어요 :

X-Powered-By: PHP/5.3.21 Content-type: text/html sh: fork: retry: Resource temporarily unavailable sh: fork: retry: Resource temporarily unavailable sh: fork: retry: Resource temporarily unavailable sh: fork: retry: Resource temporarily unavailable X-Powered-By: PHP/5.3.21 Content-type: text/html sh: fork: retry: Resource temporarily unavailable sh: fork: retry: Resource temporarily unavailable sh: fork: retry: Resource temporarily unavailable sh: fork: retry: Resource temporarily unavailable sh: fork: Resource temporarily unavailable X-Powered-By: PHP/5.3.21 Content-type: text/html 2540000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 

편집 2 : 그 다음 한 번 더 명령을하려고하는 것 같습니다 사람이 왜 알고 있나요?

EDIT 3 : 명령을 .sh 파일에 넣고 실행하려고했습니다. CLI에서 작동하지만 다시 PHP에서 작동하지 않습니다.

chdir('/'); 
$handle = exec(". /home/donor/public_html/batch/test.sh"); 

동일한 결과가 나옵니다.

+0

당신은 ($ 핸들) – m79lkm

+0

"X-구동 - 기준 : PHP/5.3.21 콘텐츠 형식 : text/html 문자열 (641)"위해서 var_dump 때 당신은 무엇을 어떻게해야합니까 X를 -Powered-By : PHP/5.3.21 내용 유형 : text/html string (573) – briandonor

답변

1

해보십시오 경유 intead, 그것은 잠시 걸리는 경우 실행에 어떤 제한이없는 그런 식 :

<?php 

passthru("/usr/bin/php /home/donor/public_html/batch/testlaunch.php",$pass_result,$error); 
echo $pass_result; 
echo $error; 

?> 
+0

위의 편집 추가 – briandonor

0

보십시오 그룹에 웹 서버에 사용자를 추가 :

<?php 

passthru("/usr/bin/php /home/donor/public_html/batch/testlaunch.php 2>&1",$pass_result); 
echo $pass_result; 

?> 

또는이 배치 디렉토리에 대한 rw 권한이 있어야합니다. 어느 루트 또는 사용 sudo를 같은 :

usermod -G groupname username 

후 배치 디렉토리에 :

chmod -R g+w batch 
+0

권한이 이미 755 – m79lkm

+0

이므로 chmod를 사용할 필요가 없습니다. 쓰기 권한을 부여하면 페이지를 방문 할 때 내부 서버 오류가 발생하고 배치 폴더는 이미 웹 사용자 – briandonor

+0

게시물을 다시 읽는 기증자 기증자입니다. shell_exec이/usr/bin/php를 가리키고 있으며 사용자의 설명에서/bin/php을 참조했음을 확인했습니다. 'which php'를 사용하여 서버상의 PHP 위치를 확인하십시오. – m79lkm

0

분명히 내가 잘못 PHP 파일/경로 도움말들에 대한 더미 감사처럼> <을 사용했다

+0

감사합니다 @ andrewsi 나는 올바른 경로를 얻으려면 PHP를 사용 – briandonor

0

이것은 오래된 게시물이지만, 여기에 다른 사용자를위한 답변입니다.

  1. 변경 실행
  2. 의 경로없이 실행 경로에 디렉토리
  3. 통화 shell_exec()가 원래의 디렉토리를 되돌리기 (코드의 다른 부분이 방해되지 않도록).

$current_dir = getcwd(); 
$executable_dir = "\executables\"; 
chdir($executable_dir); 

$output1 = shell_exec("executable.exe file_to_run.ext $parameter_to_pass"); 
var_dump($output1); 

chdir($current_dir);