PHP script is killed without explanation

前端 未结 5 645
失恋的感觉
失恋的感觉 2021-01-19 17:22

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

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

There is no output while the php script i

相关标签:
5条回答
  • 2021-01-19 17:34

    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.

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

    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

    0 讨论(0)
  • 2021-01-19 17:40

    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

    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.

    references: Who "Killed" my process and why?

    0 讨论(0)
  • 2021-01-19 17:46

    Killed is what bash says when a process exits after a SIGKILL, it's not related to putty.

    Terminated is what bash says when a process exits after a a SIGTERM.

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

    Return code when OOM killer kills a process

    0 讨论(0)
  • 2021-01-19 17:51

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

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

    Create this PHP script called m.php and save it:

    <?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 php and there are clues:

    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.

    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.
    0 讨论(0)
  • 2021-01-19 17:56

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

    Try using nohup before your command.

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

    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.

    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.

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

    nohup php -f 'yourscript'.php
    
    0 讨论(0)
提交回复
热议问题