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コードを使用する方法は、この状況に合致した場合、5秒後にurl2bmp.exeを終了しますか?

もう1つの質問は、サイトは新しいieのウィンドウでポップアップ広告、どのようにPHPでウィンドウを開くことを停止するには?ありがとう。

+0

ポップアップについてのクローズドな質問に答えるには、IEはhtml/javascriptソースを解釈してこれらのポップアップを開きます。私はあなたがPHPでそれをやっている場合は驚かれるだろう。だからそれは問題ではありません。また、[実際の](http://www.google.com/chrome)[ブラウザ](http://www.getfirefox.net/)の使用を検討してください。 – marcog

答えて

1

タイムアウトを設定することはできませんが、5秒のタイムアウトを過ぎるとプロセスを監視して終了できます。 Windows版のコード(here)があります(here:Linux)。 は実行するコマンドで、$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

こんにちは、私は多くの時間をかけましたが、私のコードでこれをどのように組み合わせるかはまだ分かりません。あなたは私をもっと助けてくれる?ありがとう。 –