bash - PHP script is killed without explanation - Stack Overflow


本站和网页 https://stackoverflow.com/questions/20520194/php-script-is-killed-without-explanation 的作者无关,不对其内容负责。快照谨为网络故障时之索引,不代表被搜索网站的即时页面。

bash - PHP script is killed without explanation - Stack Overflow
Stack Overflow
About
Products
For Teams
Stack Overflow
Public questions & answers
Stack Overflow for Teams
Where developers & technologists share private knowledge with coworkers
Talent
Build your employer brand
Advertising
Reach developers & technologists worldwide
About the company
s-popover#show"
data-s-popover-placement="bottom-start" />
Loading…
current community
Stack Overflow
help
chat
Meta Stack Overflow
your communities
Sign up or log in to customize your list.
more stack exchange communities
company blog
Log in
Sign up
Home
Public
Questions
Tags
Users
Companies
Collectives
Explore Collectives
Teams
Stack Overflow for Teams
– Start collaborating and sharing organizational knowledge.
Create a free Team
Why Teams?
Teams
Create free Team
Collectives™ on Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most.
Learn more about Collectives
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Learn more about Teams
PHP script is killed without explanation
Ask Question
Asked
9 years ago
Modified
8 years, 9 months ago
Viewed
15k times
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 is running.
After a time, the php script responds with:
Killed
My idea is that it reached the 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 Killed phrase mean?
phpbashputty
Share
Improve this question
Follow
edited Mar 13, 2014 at 17:55
Eric Leschinski
141k9494 gold badges406406 silver badges331331 bronze badges
asked Dec 11, 2013 at 13:17
Robin93KRobin93K
17622 gold badges33 silver badges1515 bronze badges
putty session and all its running process is killed when the shell ends. use nohup before command
– bansi
Dec 11, 2013 at 13:20
Just terminology maybe, but for better understanding: putty is just the thing that lets you open an SSH session to your server. It is really unlikely that putty is killing your process. You are in a session, and somthing killes your process. And you see it in the session (putty makes the session).
– Nanne
Dec 11, 2013 at 13:20
Seeing all the nohup answers: your session is still running right? you can just do an 'ls' after you see 'killed' ? If so, those answers will probably not help you...
– Nanne
Dec 11, 2013 at 13:22
@bansi, funnily I really tried it, even so that I didn't closed the session, without success...
– Robin93K
Dec 11, 2013 at 13:24
@Nanne Yeah I know that it only connects me with our server, but there is nothing on the server, as soon as I know, which could kill my process...
– Robin93K
Dec 11, 2013 at 13:25
Show 2 more comments
5 Answers
Sorted by:
Reset to default
Highest score (default)
Trending (recent votes count more)
Date modified (newest first)
Date created (oldest first)
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?
Share
Improve this answer
Follow
edited May 23, 2017 at 12:25
CommunityBot
111 silver badge
answered Dec 11, 2013 at 13:24
NanneNanne
63.8k1616 gold badges118118 silver badges161161 bronze badges
Is there any function for PHP to check the current Swap Usage or a bash cmd to check live how mush Swap is used ?
– Robin93K
Dec 11, 2013 at 13:50
sure. Log in separately while running (or run your command in the background, and use commands like top and free to check on your server state, though complete run-trought of this might be somewhat beyond scope of this question. Try to look up the manpage.
– Nanne
Dec 11, 2013 at 13:53
where can I see the Swap usage? I only see the memory usage.
– Robin93K
Dec 11, 2013 at 14:12
sry... forget that question I was kinda blind xD
– Robin93K
Dec 11, 2013 at 14:30
Someone should add to this answer, that it is pretty hard to figure out when set_time_limit() is set, since it doesn't show any "Killed" in php terminal or so, which is different from memory_limit behaviour
– shakaran
Jul 29, 2016 at 3:33
Show 1 more comment
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:
Increase the amount of RAM available.
Break down the problem set into smaller chunks that operate sequentially.
Rewrite the program so it has a much smaller memory requirements.
Share
Improve this answer
Follow
answered Mar 13, 2014 at 17:58
Eric LeschinskiEric Leschinski
141k9494 gold badges406406 silver badges331331 bronze badges
Add a comment
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
Share
Improve this answer
Follow
edited May 23, 2017 at 12:09
CommunityBot
111 silver badge
answered Dec 11, 2013 at 13:23
mr.spuraticmr.spuratic
9,57733 gold badges3333 silver badges2424 bronze badges
I'd say you don't run in to php limits, as you'd see an error instead of a sigkill!
– Nanne
Dec 11, 2013 at 13:25
@Nanne facepalm. I really should read my own answers more carefully, fixed thx!
– mr.spuratic
Dec 11, 2013 at 13:29
@mr-spuratic I'D like to check that, is there any PHP-version of WIFSIGNALED() & WTERMSIG()? or where shallI let them run?
– Robin93K
Dec 11, 2013 at 13:54
Those are only of use in the parent process to see what happened to a child. That said, see PHP's pcntl functions. memory_get_peak_usage() might be useful too. I don't think PHP has enough signal support to find details of a received signal.
– mr.spuratic
Dec 12, 2013 at 10:26
Add a comment
-2
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
Share
Improve this answer
Follow
answered Dec 11, 2013 at 13:22
Acelasi EuAcelasi Eu
91422 gold badges99 silver badges3030 bronze badges
Add a comment
-2
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
Share
Improve this answer
Follow
edited Dec 12, 2013 at 4:40
answered Dec 11, 2013 at 13:21
Prabhat KumarPrabhat Kumar
31011 silver badge88 bronze badges
Assuming the session still runs (you do see 'killed' after all), I see no reason why there should be a hangup?
– Nanne
Dec 11, 2013 at 13:22
Add a comment
Your Answer
Thanks for contributing an answer to Stack Overflow!Please be sure to answer the question. Provide details and share your research!But avoid …Asking for help, clarification, or responding to other answers.Making statements based on opinion; back them up with references or personal experience.To learn more, see our tips on writing great answers.
Draft saved
Draft discarded
Sign up or log in
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Submit
Post as a guest
Name
Email
Required, but never shown
Post as a guest
Name
Email
Required, but never shown
Post Your Answer
Discard
By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy
Not the answer you're looking for? Browse other questions tagged phpbashputty or ask your own question.
The Overflow Blog
I spent two years trying to do what Backstage does for free
The complete guide to protecting your APIs with OAuth2 (part 1)
Featured on Meta
Navigation and UI research starting soon
2022 Community Moderator Election Results - now with two more mods!
Temporary policy: ChatGPT is banned
I'm standing down as a moderator
Linked
774
What killed my process and why?
39
How can I tell in Linux which process sent my process a signal
14
Laravel queues getting "killed"
10
Return code when OOM killer kills a process
-2
importing huge sql file using php command line
Related
4258
How do I check if a directory exists in a Bash shell script?
5931
How do I get the directory where a Bash script is located from within the script itself?
2773
How can I prevent SQL injection in PHP?
2974
Deleting an element from an array in PHP
2902
How can I check if a program exists from a Bash script?
2071
How to reload .bashrc settings without logging out and back in again?
4995
Reference — What does this symbol mean in PHP?
1838
Check existence of input argument in a Bash shell script
2245
How does PHP 'foreach' actually work?
2689
Why shouldn't I use mysql_* functions in PHP?
Hot Network Questions
How can I calculate gravitational time dilation between two planets?
Table row to fill entire page
RISC-V Zero Instruction Question
Has Zelensky has "declared war against Christianity"?
8086 Segment Address to Linear
Can one enforce a patent while it is only "pending approval"?
Will a tri bike improve my speed?
How can I make sure my Roll For Shoes character gets XP or new skills?
Is Evelyn pronounced variously based on gender?
Circular shape with sine edge
What are good heat-resistant materials for writing a self-immolating spellbook?
How should I investigate and respond to a potentially false claim of a publication in the CV of an applicant?
What does the qualifier NOMINAL exactly refer to?
Electric backup just for heating system?
Does it make sense to call GAP a "procedural" language?
Keep elements in sequence that have a letter repeated at least 3 times
Fuel for vehicles in an abruptly abandoned world
Selecting rows in attribute table by date (QGIS)
Where would the first nuke have been dropped in Germany?
How does laptop 'limit battery charge' work?
The World Cup final conspiracy
Why isn't heat conduction considered a form of work?
How do I pass an objective bound to Gurobi?
Is it possible to have the contract starting date before actually starting to work?
more hot questions
Question feed
Subscribe to RSS
Question feed
To subscribe to this RSS feed, copy and paste this URL into your RSS reader.
default
Stack Overflow
Questions
Help
Products
Teams
Advertising
Collectives
Talent
Company
About
Press
Work Here
Legal
Privacy Policy
Terms of Service
Contact Us
Cookie Settings
Cookie Policy
Stack Exchange Network
Technology
Culture & recreation
Life & arts
Science
Professional
Business
API
Data
Blog
Facebook
Twitter
LinkedIn
Instagram
Site design / logo 2022 Stack Exchange Inc; user contributions licensed under CC BY-SA. rev 2022.12.21.43127
Your privacy
By clicking “Accept all cookies”, you agree Stack Exchange can store cookies on your device and disclose information in accordance with our Cookie Policy.
Accept all cookies
Customize settings