PHP 中的系统($cmd)超时
我使用 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?
还有一个问题,网站会在新的ie窗口中弹出广告,如何用php阻止打开新的ie窗口?谢谢。
I am use url2bmp.exe to catch site screenshoot with php. my code like:
<?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);
?>
but some time, the site page has some loading problems and the url2bmp will stop in this site and never close itself still waiting loading the page. how to use php code terminate url2bmp.exe after run in 5 seconds if it met this situation?
And another question, the site will pop-up ads in a new ie windows, how to stop open a new ie windows with php? Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您无法设置超时,但您可以监视进程并在超过 5 秒超时后将其终止。以下是 Windows 上的一些代码(来自此处)(请参阅此处(适用于 Linux)。
$command
是要执行的命令,$timeout
是让进程运行的时间(在您的情况下为 5 秒),$sleep
是超时检查之间的间隔(1 秒应该适合您的情况)。You can't set a timeout, but you can monitor the process and kill it if it passes the 5 second timeout. Here's some code (from here) on Windows (see here for Linux).
$command
is the command to execute,$timeout
is how long to let the process run for (5 seconds in your case) and$sleep
is the interval between timeout checks (1 second should be suitable for your case).