Php关闭窗口x经过一段时间后

时间:2023-01-20 17:03:52

I'm running apache, php, mysql on windows 7. I'm using windows task schedule to open a 'cron job' (php script) on my localhost server. In php I would like to close that tab in the window after 30 minutes (to ensure the script has operated). I know how to do it in javascript using setTimeout() and window.close() functions, but I'm avoiding javascript in this code. Is there a way to do it in php? Or if anyone knows how to do it in windows task scheduler, that would be good too.

我在Windows 7上运行apache,php,mysql。我正在使用Windows任务计划在我的localhost服务器上打开'cron job'(php脚本)。在php中我想在30分钟后关闭窗口中的该选项卡(以确保脚本已运行)。我知道如何使用setTimeout()和window.close()函数在javascript中执行此操作,但我在此代码中避免使用javascript。有没有办法在PHP中做到这一点?或者,如果有人知道如何在Windows任务调度程序中执行此操作,那也会很好。

Anytime I searched for it on google, all that popped up was the javascript way of closing a window.

任何时候我在谷歌搜索它,所有弹出的是关闭窗口的JavaScript方式。

2 个解决方案

#1


0  

If You don't need to see what You page displays, instead of using web browser, use some non-interactive tool that fetches websites, like wget or cURL. Both of them should be available as executable windows binaries. This will keep same behaviour for PHP script like normal webbrowser visit, except javascript which, you mentioned, wish to avoid, and will be not executed. Wget or cURL will only fetch content of generated page.

如果您不需要查看您显示的页面,而不是使用Web浏览器,请使用一些非交互式工具来获取网站,例如wget或cURL。它们都应该可用作可执行的Windows二进制文件。这将保持PHP脚本的相同行为,如正常的webbrowser访问,除了javascript,你提到,希望避免,并且将不会执行。 Wget或cURL只会获取生成页面的内容。

Wget - http://gnuwin32.sourceforge.net/packages/wget.htm

Wget - http://gnuwin32.sourceforge.net/packages/wget.htm

cURL - http://curl.haxx.se/download.html (on the bottom of page You have several version of cURL for windows).

cURL - http://curl.haxx.se/download.html(在页面底部你有几个版本的cURL for windows)。

#2


0  

The following code would open the IE browser with the URL mentioned ($url) and in the sleep parameters pass the time upto which you want the window to remain opened (parameter is in seconds).

以下代码将使用提到的URL($ url)打开IE浏览器,并在sleep参数中传递您希望窗口保持打开的时间(参数以秒为单位)。

//The code starts from here:
$browser = new COM("InternetExplorer.Application");
$handle = $browser -> HWND;
$browser -> Visible = true;
$browser -> Width = 1100;
$browser -> Height = 700;
//$url=your url you want to open
print_r($browser -> Navigate($url));
while ($browser -> Busy) 
{
      com_message_pump(5000);
}
//The time you think is sufficient to open your web page
sleep(10);
$browser -> Quit();

#1


0  

If You don't need to see what You page displays, instead of using web browser, use some non-interactive tool that fetches websites, like wget or cURL. Both of them should be available as executable windows binaries. This will keep same behaviour for PHP script like normal webbrowser visit, except javascript which, you mentioned, wish to avoid, and will be not executed. Wget or cURL will only fetch content of generated page.

如果您不需要查看您显示的页面,而不是使用Web浏览器,请使用一些非交互式工具来获取网站,例如wget或cURL。它们都应该可用作可执行的Windows二进制文件。这将保持PHP脚本的相同行为,如正常的webbrowser访问,除了javascript,你提到,希望避免,并且将不会执行。 Wget或cURL只会获取生成页面的内容。

Wget - http://gnuwin32.sourceforge.net/packages/wget.htm

Wget - http://gnuwin32.sourceforge.net/packages/wget.htm

cURL - http://curl.haxx.se/download.html (on the bottom of page You have several version of cURL for windows).

cURL - http://curl.haxx.se/download.html(在页面底部你有几个版本的cURL for windows)。

#2


0  

The following code would open the IE browser with the URL mentioned ($url) and in the sleep parameters pass the time upto which you want the window to remain opened (parameter is in seconds).

以下代码将使用提到的URL($ url)打开IE浏览器,并在sleep参数中传递您希望窗口保持打开的时间(参数以秒为单位)。

//The code starts from here:
$browser = new COM("InternetExplorer.Application");
$handle = $browser -> HWND;
$browser -> Visible = true;
$browser -> Width = 1100;
$browser -> Height = 700;
//$url=your url you want to open
print_r($browser -> Navigate($url));
while ($browser -> Busy) 
{
      com_message_pump(5000);
}
//The time you think is sufficient to open your web page
sleep(10);
$browser -> Quit();