I am trying to run a PHP script to select info from a MySQL database. Here's a simple test script:
$link = mysqli_connect($host, $user, $password, $database) or die("Error" . mysqli_error($link));
if (!mysqli_set_charset($link, "utf8")) { printf("Ошибка при загрузке набора символов utf8: %s\n", mysqli_error($link));
} else {
$encod="encoding_ok";
}
echo "YO!!";
$query ="SELECT * FROM `spravka` LIMIT 500000";
$result = mysqli_query($link, $query) or die("error" . mysqli_error($link));
$pp="0";
echo "Did select!!"; while($array_a = mysqli_fetch_assoc($result)) {
$pp++;
..
}
echo $$pp;
?>The script is getting killed by ubuntu kernel.
The log shows
Apr 29 19:03:19 55234 kernel: [ 4261.409964] Out of memory: Kill process 5043 (php) score 507 or sacrifice child
Apr 29 19:03:19 55234 kernel: [ 4261.409967] Killed process 5043 (php) total-vm:454812kB, anon-rss:273600kB, file-rss:0kB" I checked the Id of the process ps aux | grep php I got a different process ID from what I see in the log for some reason but I change oom for both ... )
I increased memory for the PHP process
sudo bash -c "echo '-15' /proc/10600/oom_adjThen I increased it again
sudo bash -c "echo '-1000' /proc/10600/oom_scope_adjBut it didn't help.
What am I doing wrong?
How I'm checking - I change SIZE of request to SQL by choosing LIMIT 300 000 - it's working number but LIMIT 400 000 already not on every oom_adj parameters - so it's means no changes performed...
I tried to reboot system - no result.
My system: Ubuntu 12.04 / php 5 / Mysql 512mb RAM (not much but should be good enough for one script !)
And small second question why I have one Proces ID from my command in shell and another one in my logfile for same program (php) ?
1 Answer
If the OOM killer is being invoked, it means your system's physical RAM and swap are both full. No amount of tinkering with /proc or php.ini will fix this. You've got three options:
- Increase the size of the swap space.
- Install more RAM.
- Re-write your program to be more memory-efficient.