Where The Streets Have No Name

php에서 비동기 처리 본문

Developement/PHP

php에서 비동기 처리

highheat 2012. 8. 21. 18:11

참고 : http://robert.accettura.com/blog/2006/09/14/asynchronous-processing-with-php/

 

브라우저에서 호출되는 페이지

<?php
/* Note that the call itself isn’t sanitized in any way, so it’s
   important to make sure that this can’t be exploited, see
   docs for escapeshellcmd() for details
*/
 
// Demonstration
if(launchBackgroundProcess('php d:/temp2/convert.php')){
    print 'Successfully launched background process';
}
 
 
 
/**
* Launch Background Process
*
* Launches a background process (note, provides no security itself, $call must be sanitized prior to use)
* @param string $call the system call to make
* @author raccettura
*/
function launchBackgroundProcess($call) {
	
    // Windows
    if(is_windows()){
        pclose(popen('start /b '.$call, 'r'));        
    }
 
    // Some sort of UNIX
    else {
        pclose(popen($call.' /dev/null &', 'r'));
    }
    return true;
}
 
 
/**
* Is Windows
*
* Tells if we are running on Windows Platform
* @author raccettura
*/
function is_windows(){
    if(PHP_OS == 'WINNT' || PHP_OS == 'WIN32'){
        return true;
    }
    return false;
}
?>
백그라운드로 실행되는 페이지
<?
$cnt = shell_exec('identify -density 10 -format %n d:/temp2/0806daemun_vol2_08.pdf');

for ($i = 0; $i < $cnt; $i++) {
	$output = shell_exec('convert -density 200 d:/temp2/0806daemun_vol2_08.pdf['.$i.'] -resize 1275x1816 -colorspace RGB d:/temp2/image/aaa_'.$i.'.jpg');
}
?>