杀死后台php脚本(共享主机)

发布于 2024-12-02 12:28:30 字数 146 浏览 1 评论 0原文

我使用ignore_user_abort()函数创建了一个在后台运行的脚本。然而,我很愚蠢,没有插入任何类型的代码来使脚本停止,现在它每 30 秒发送一次电子邮件......

有什么方法可以停止脚本吗?我位于共享主机中,因此无法访问命令提示符,也不知道 PID。

I created a script that runs in the background using the ignore_user_abort() function. However, I was foolish enough not to insert any sort of code to make the script stop and now it is sending e-mails every 30 seconds...

Is there any way to stop the script? I am in a shared hosting, so I don't have access to the command prompt, and I don't know the PID.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

清风疏影 2024-12-09 12:28:30

有什么办法可以停止脚本吗?我位于共享主机中,因此无法访问命令提示符,也不知道 PID。

那么不。

但您确定您没有任何 shell 访问权限吗?即使通过 PHP 也可以吗?如果你这样做,你可以尝试......

<?php

print `ps -ef | grep php`;

如果你可以从中识别进程,那么......

<?php

$pid=12345; // for example.
print `kill -9 $pid`;

即使你无权运行 shell 命令,你也可以找到 pid在 /proc (在 Linux 系统上)并使用 POSIX 扩展终止它......

<?php

$ps=glob('/proc/[0-9]*');
foreach ($ps as $p) {
    if (is_dir($p) && is_writeable($p)) {
        print "proc= " . basename($p);
        $cmd=file_get_contents($p . '/cmdline');
        print " / " . file_get_contents($p . '/cmdline');
        if (preg_match('/(php).*(myscript.php)/',$cmd)) {
            posix_kill(basename($p), SIGKILL);
            print " xxxxx....";
            break;
        }
        print "\n";
    }  
}

Is there any way to stop the script? I am in a shared hosting, so I don't have access to the command prompt, and I don't know the PID.

Then no.

But are you sure you don't have any shell access? Even via PHP? If you do, you could try....

<?php

print `ps -ef | grep php`;

...and if you can identify the process from that then....

<?php

$pid=12345; // for example.
print `kill -9 $pid`;

And even if you don't have access to run shell commands, you may be able to find the pid in /proc (on a linux system) and terminate it using the POSIX extension....

<?php

$ps=glob('/proc/[0-9]*');
foreach ($ps as $p) {
    if (is_dir($p) && is_writeable($p)) {
        print "proc= " . basename($p);
        $cmd=file_get_contents($p . '/cmdline');
        print " / " . file_get_contents($p . '/cmdline');
        if (preg_match('/(php).*(myscript.php)/',$cmd)) {
            posix_kill(basename($p), SIGKILL);
            print " xxxxx....";
            break;
        }
        print "\n";
    }  
}
陈年往事 2024-12-09 12:28:30

我昨天就来到这个话题了!我错误地在一个不应该被访问的页面中出现了无限循环,这将我的 I/O 增加到了 100,CPU 使用率增加到了 100 I/ O 是因为一些 php 错误,它正在被记录,并且日志文件大小的增长超出了任何人的想象。

上述技巧在我的共享主机上都不起作用。

我的解决方案

  1. 在 cPanel 中,转到 PHP 版本(当前版本除外)

  2. 选择任意 PHP 版本暂时。

  3. 然后应用更改

它工作的原因

具有一些 php 错误的无限循环的脚本是一个进程,所以我只需要杀死它,更改 php 版本以加强 php 和 Apache 等服务的重新启动,并且因为之前涉及重新启动进程被终止,随着 I/OCPU 使用稳定下来,我感到放松。另外,我在手动更改 php 版本之前修复了该错误:)

I came to this thread Yesterday! I by mistake had a infinite loop in a page which was not supposed to be visited and that increased my I/O to 100 and CPU usage to 100 I/O was because of some php errors and it was getting logged and log file size was increasing beyond anyone can think.

None of the above trick worked on my shared hosting.

MY SOLUTION

  1. In cPanel, go to PHP Version (except that of current)

  2. Select any PHP Version for time being.

  3. And then Apply Changes.

REASON WHY IT WORKED

The script which had infinite loop with some php errors was a process so I just needed to kill it, changing php version reinforce restart of services like php and Apache, and as restart was involved earlier processes were killed, and I was relaxed as I/O and CPU usage stabilized. Also, I fixed that bug before hand changing the php version :)

不顾 2024-12-09 12:28:30

你是如何部署脚本的?当然你可以删除它(如果这是一个可接受的选项)。否则修改它并插入一些逻辑,只允许它根据服务器时间每 n 分钟/小时/天发送一次邮件?

关于。停止脚本执行(或者更确切地说是系统尝试执行它),您是如何安排它执行的?它是某种类型的 crontab 图形用户界面还是其他什么?你能不只是撤消你在那里所做的事情吗(因为你无法访问命令行/终端)?

罗布·甘利

how did you deploy the script? surely you can just remove it (if that's an acceptable option). otherwise modify it and insert some logic to only allow it to send a mail once every n mins/hours/days based on the server time?

re. stopping the script from executing (or rather the system trying to execute it) how did you schedule it for execution? is it some type of gui to a crontab or something? can you not just undo what you did there (seeing as you have no access to the command line/terminal)?

rob ganly

孤寂小茶 2024-12-09 12:28:30

简单地 。
打电话给支持,取消它。
下次,不要执行你无法控制的事情。

Simply .
Call the support, get it cancelled.
Next time, don't execute something you can't control.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文