bash PHP脚本被杀,不解释

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20520194/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 08:57:40  来源:igfitidea点击:

PHP script is killed without explanation

phpbashputty

提问by Robin93K

I'm starting my php script in the following way:

我正在以下列方式启动我的 php 脚本:

bash  
cd 'path'   
php -f 'scriptname'.php

There is no output while the php script is running.

php 脚本运行时没有输出。

After a time, the php script responds with:

一段时间后,php 脚本响应如下:

Killed 

My idea is that it reached the memory_limit: ini_set('memory_limit', '40960M');

我的想法是它达到了memory_limit: ini_set('memory_limit', '40960M');

Increasing the memory limit seemed to solve the problem, but it only increased the edge.

增加内存限制似乎解决了问题,但它只是增加了优势。

What exactly does that Killedphrase mean?

Killed句话究竟是什么意思?

回答by Nanne

Your process is killed. There could be a multitude of reasons, but it's easy to discard some of the more obvious.

你的进程被杀死了。可能有多种原因,但很容易丢弃一些更明显的原因。

  • php limits: if you run into a php limit, you'll get an error in the logfile, and probably on the commandline as well. This normally does not print 'killed'
  • the session-is-ended-issues: if you still have your session, then your session is obvioiusly not ended, so disregard all the nohup and &stuff
  • php 限制:如果遇到 php 限制,您将在日志文件中收到错误消息,并且可能在命令行中也会出现错误。这通常不会打印 'killed'
  • session-is-ended-issues:如果你还有你的 session,那么你的 session 显然没有结束,所以忽略所有的 nohup 和&东西

If your server is starved for resources (no memory, no swap), the kernel might kill your process. This is probably what's happening.

如果您的服务器资源匮乏(没有内存,没有交换),内核可能会终止您的进程。这大概就是正在发生的事情。

In anycase: your process is getting send a signal that it should stop. Normally only a couple of 'things' can do this

无论如何:您的进程正在发送一个应该停止的信号。通常只有几个“事情”可以做到这一点

  • your account (e.g. you kill the process)
  • an admin user (e.g. root)
  • the kernel when it is really needing your memory for itself.
  • maybe some automated process, for instance, if you live on a shared server and you take up more then your share of resources.
  • 您的帐户(例如您终止进程)
  • 管理员用户(例如 root)
  • 当内核真正需要你的内存时。
  • 也许是一些自动化过程,例如,如果您住在共享服务器上并且您占用的资源比您的资源份额多。

references: Who "Killed" my process and why?

参考资料:谁“杀死”了我的进程,为什么?

回答by Eric Leschinski

You could be running out of memory in the PHP script. Here is how to reproduce that error:

您可能会在 PHP 脚本中耗尽内存。以下是重现该错误的方法:

I'm doing this example on Ubuntu 12.10 with PHP 5.3.10:

我正在使用 PHP 5.3.10 在 Ubuntu 12.10 上做这个例子:

Create this PHP script called m.phpand save it:

创建这个名为的 PHP 脚本m.php并保存它:

<?php
    function repeat(){
       repeat();
    }
    repeat();
?>

Run it:

运行:

el@apollo:~/foo$ php m.php
Killed

The program takes 100% CPU for about 15 seconds then stops. Look at dmesg | grep phpand there are clues:

该程序占用 100% CPU 约 15 秒,然后停止。看了一下dmesg | grep php,有蛛丝马迹:

el@apollo:~/foo$ dmesg | grep php
[2387779.707894] Out of memory: Kill process 2114 (php) score 868 or 
sacrifice child

So in my case, the PHP program printed "Killed" and halted because it ran out of memory due to an infinite loop.

所以在我的例子中,PHP 程序打印“Killed”并停止,因为它由于无限循环而耗尽内存。

Solutions:

解决方案:

  1. Increase the amount of RAM available.
  2. Break down the problem set into smaller chunks that operate sequentially.
  3. Rewrite the program so it has a much smaller memory requirements.
  1. 增加可用的 RAM 量。
  2. 将问题集分解为按顺序运行的较小块。
  3. 重写程序,使其具有更小的内存需求。

回答by mr.spuratic

Killedis what bashsays when a process exits after a SIGKILL, it's not related to putty.

Killedbash在 SIGKILL 后退出进程时所说的,它与 putty 无关。

Terminatedis what bashsays when a process exits after a a SIGTERM.

Terminatedbash在 SIGTERM 后退出进程时所说的话。

You are not running into PHP limits, you may be running into a different problem, see:

您没有遇到PHP 限制,您可能遇到了不同的问题,请参阅:

Return code when OOM killer kills a process

当 OOM 杀手杀死进程时返回代码

回答by Prabhat Kumar

If you are already taking care of php.ini settings related with script memory and timeout then may be its linux ssh connection which terminating in active session or some thing like that.

如果您已经在处理与脚本内存和超时相关的 php.ini 设置,那么可能是它的 linux ssh 连接在活动会话中终止或类似的事情。

You can use 'nohup' linux command run a command immune to hangups

您可以使用 'nohup' linux 命令运行一个不受挂起影响的命令

shell> nohup php -f 'scriptname'.php

Edit:- You can close your session by adding '&' at end of command:-

编辑:- 您可以通过在命令末尾添加“&”来关闭会话:-

shell> nohup php -f 'scriptname'.php &> /dev/null &

'&' operater at end of any comand in linux move that command in background

linux中任何命令末尾的'&'操作符都会在后台移动该命令

回答by Acelasi Eu

http://en.wikipedia.org/wiki/Nohup

http://en.wikipedia.org/wiki/Nohup

Try using nohup before your command.

在您的命令之前尝试使用 nohup。

nohup catches the hangup signal while the ampersand doesn't (except the shell is confgured that way or doesn't send SIGHUP at all).

nohup 捕获挂断信号,而&符号则没有(除了外壳以这种方式配置或根本不发送 SIGHUP)。

Normally, when running a command using & and exiting the shell afterwards, the shell will terminate the sub-command with the hangup signal (kill -SIGHUP ). This can be prevented using nohup, as it catches the signal and ignores it so that it never reaches the actual application.

通常,当使用 & 运行命令并随后退出 shell 时,shell 将使用挂断信号(kill -SIGHUP )终止子命令。这可以使用 nohup 来防止,因为它捕获信号并忽略它,因此它永远不会到达实际应用程序。

In case you're using bash, you can use the command shopt | grep hupon to find out whether your shell sends SIGHUP to its child processes or not. If it is off, processes won't be terminated, as it seems to be the case for you.

如果您使用 bash,您可以使用命令 shopt | grep hupon 以确定您的 shell 是否将 SIGHUP 发送到其子进程。如果它关闭,进程将不会被终止,就像你的情况一样。

There are cases where nohup does not work, for example when the process you start reconnects the NOHUP signal.

在某些情况下 nohup 不起作用,例如当您启动的进程重新连接 NOHUP 信号时。

nohup php -f 'yourscript'.php