gpt4 book ai didi

php 脚本在 Linux 启动时不执行

转载 作者:太空宇宙 更新时间:2023-11-04 04:15:14 25 4
gpt4 key购买 nike

每当我启动我的机器 (Linux) 时,我都需要一些通知。因此,我创建了一个 php 脚本,它有一些逻辑,我希望每当登录我的机器时都能在浏览器中看到脚本的输出。

我已在/etc/rc.local 中添加了我的 php 文件。但我的浏览器在启动后打不开。可能是它在启动后无法找到 google-chrome 的实例。

还有其他建议吗,以便我可以在登录后立即弹出窗口?

我的 php 脚本(tasks.php):

$popUp = "Test task";
$popUp = "<html>$popUp</html>";
$fp = fopen("<path_to_file>/tasks.htm","w");
fwrite($fp,$popUp);
fclose($fp);
exec("google-chrome <path_to_file>/tasks.htm");

/etc/rc.local:

#!/bin/sh
#
# This script will be executed *after* all the other init scripts.
# You can put your own initialization stuff in here if you don't
# want to do the full Sys V style init stuff.

php <path_to_file>/tasks.php

最佳答案

google chrome在系统初始化期间无法启动 - 首先,窗口系统尚未准备好,而且您的帐户(创建 X session )尚未登录。

但是,您可以基于 PHP 脚本(脚本中的 CLI)的执行来编写页面,例如/tmp

$fp = fopen("/tmp/myaccount.tasks.htm","w");

然后,当您登录时,google chrome 会自动启动,并将创建的文件作为参数。例如

/usr/bin/google-chrome /tmp/myaccount.tasks.htm

This link解释如何在登录时启动程序。 (如果您不使用 Ubuntu,请参阅已接受答案底部的 ~/.config/autostart 路径)

关于php 脚本在 Linux 启动时不执行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16790894/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com