2011-01-12 28 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代碼在5秒內運行後終止url2bmp.exe如果遇到這種情況?

而另一個問題,該網站將彈出廣告在一個新的即Windows,如何停止開放一個新的,即與Windows窗口?謝謝。

+0

要回答關於彈出窗口的結束問題:IE通過解釋html/javascript源打開這些彈出窗口。如果你在php中這樣做,我會感到驚訝。所以它不應該是一個問題。請考慮使用[真實](http://www.google.com/chrome)[瀏覽器](http://www.getfirefox.net/)。 – marcog 2011-01-12 10:37:19

回答

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

嗨,我嘗試了很多時間,但仍然不知道如何在我的代碼中結合這一點。你能幫助我嗎?謝謝。 – 2011-01-12 11:24:32