2011-01-12 6 views
2

나는 url2bmp.exe를 사용하여 PHP로 사이트 스크린 샷을 잡습니다. 내 코드는 같은 :

<?php 
$cmd = 'url2bmp.exe -url "http://www.filmgratis.tv/index.php/category/film/animazione" -format jpeg -file"C:\www\Screenshot\screenshoot.jpg" -wait 5 -notinteractive run and exit when done -removesb remove right scroll bar'; 
system($cmd); 
?> 

하지만 약간의 시간, 사이트 페이지가 일부 로딩 문제가 있고 url2bmp이 사이트에서 중지하고 자체는 여전히 페이지를로드 기다리고 종료하지 않습니다. PHP 코드를 사용하는 법은 url2bmp.exe를 5 초 후에 종료합니다.

또 다른 질문, 사이트는 새로운 ie 창에서 팝업 광고, 어떻게 PHP를 사용하여 새 창을 열지 않습니까? 감사.

+0

팝업에 관한 폐문에 대한 답변 : IE는 html/javascript 소스를 해석하여 이러한 팝업을 엽니 다. PHP에서 그렇게한다면 놀랄 것입니다. 그래서 그것은 문제가되어서는 안됩니다. [실제] (http://www.google.com/chrome) [브라우저] (http://www.getfirefox.net/) 사용을 고려해보십시오. – marcog

답변

1

시간 제한을 설정할 수 없지만 프로세스를 모니터링하고 5 초 제한 시간이 경과하면 프로세스를 종료 할 수 있습니다. 다음은 Windows의 일부 코드 (here)입니다 (Linux의 경우 here 참조). $command은 실행 명령이며 $timeout은 프로세스가 (귀하의 경우 5 초) 실행될 수있는 시간이며 $sleep은 시간 초과 확인 간격입니다 (1 초는 귀하의 경우에 적합해야 함).

function PsExecute($command, $timeout = 60, $sleep = 2) { 
    // First, execute the process, get the process ID 

    $pid = PsExec($command); 

    if($pid === false) 
     return false; 

    $cur = 0; 
    // Second, loop for $timeout seconds checking if process is running 
    while($cur < $timeout) { 
     sleep($sleep); 
     $cur += $sleep; 
     // If process is no longer running, return true; 

     echo "\n ---- $cur ------ \n"; 

     if(!PsExists($pid)) 
      return true; // Process must have exited, success! 
    } 

    // If process is still running after timeout, kill the process and return false 
    PsKill($pid); 
    return false; 
} 

function PsExec($commandJob) { 

    $command = $commandJob.' > /dev/null 2>&1 & echo $!'; 
    exec($command ,$op); 
    $pid = (int)$op[0]; 

    if($pid!="") return $pid; 

    return false; 
} 

function PsExists($pid) { 

    exec("ps ax | grep $pid 2>&1", $output); 

    while(list(,$row) = each($output)) { 

      $row_array = explode(" ", $row); 
      $check_pid = $row_array[0]; 

      if($pid == $check_pid) { 
        return true; 
      } 

    } 

    return false; 
} 

function PsKill($pid) { 
    exec("kill -9 $pid", $output); 
} 
+0

안녕하세요, 많은 시간을 보냈지 만 여전히 내 코드에서이를 결합하는 방법을 알지 못합니다. 너 더 도움이 될 수 있니? 감사. –

관련 문제