프로그램/PHP
[PHP] exec 백그라운드 작업
주원대디
2017. 4. 27. 16:17
[PHP] exec 백그라운드 작업
curl로 통신을 하는데 데이터 전송도중에 클라이언트가
뒤로가기, 페이지이동, 창을 닫을 경우 retrun 값 처리가 불가능하여
exec 백그라운 실행으로 해결!
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 |
<?
$custMsgSn = mysql_insert_id();
$str1 = "test1";
$str2 = "test2";
$param = " {$custMsgSn} {$str1} {$str2}";
exec("/usr/local/bin/php /home/taewoo/public_html/test.php {$str1} {$str2} ", $out);
// 완전한 백그라운드가 안됨! 리턴값 가져오면서 수행
print_r($out);
//$out 출력!
exec("/usr/local/bin/php /home/taewoo/public_html/test.php". $param. " > /dev/null &");
// 완전한 백그라운드 리턴값 없이 바로 넘어감.
echo "END";
?> |
cs |
주의할점은 문자열 넘길때 띄어쓰기는 다른변수로 인식한다는것
"test 1" -> "test_1"
형태로 넘겨서 받을때 가공해서 쓰는게 좋을꺼 같다.
1
2
3
4
5
6
7
8 |
<?
$param = $_SERVER['argv'];
$custMsgSn = $param[1];
$str1 = $param[2];
$str2 = $param[3];
?> |
cs |
변수 넘겨서 받을때는 위와 같이 받으면 된다.