I am running out of memory when using command line when logged in over SSH as a user mike
.
When I run the script via browser or via command line as root
, its all good and stalls at 1000M as expected.
The test script I am using is:
<pre>
<?php
echo //phpinfo();
error_reporting(E_ALL);
ini_set('display_errors', 'on');
for ($i=1; $i<1500; $i+=50) {
$a = loadmem($i);
echo "You have allocated ". $i . "M (". memory_get_usage() . ") memory in this php script" . "<br />";
unset($a);
}
function loadmem($howmuchmeg) {
$a = str_repeat("0", $howmuchmeg * 1024 * 1024); // alocating 10 chars times million chars
return $a;
}
?>
</pre>
When I run as user mike
the script errors at around 200M.
I am using php-fpm and tried both PHP 5.6 and 7.2 and tried both memory_limit
settings as 1000M.
When I run this as mike
:
php -i | grep memory_limit
I get:
memory_limit => 1000M => 1000M
I cannot for the life of me see where it’s getting this 200M limit from.
Is there any reason why a user account would restrict memory usage over root?
2
Answers
The ini files used for your server(browser) and the cli are different.
You can either specify a configuration file using
-c
or get the location of php’s cli configuration file by$ php -i |grep php.ini
It can be file permission issue on the php.ini file.
Source: https://major.io/2007/06/14/php-cli-memory-limit-is-different-between-users-and-root/
Because you run through with apache (I think) than maybe that user can’t access the php.ini file. Also please note, for cli and for apache (script run) there’s two different ini files. Also some distributions splited up the ini files, in those case the last variable set will be applied (if the same value was set in multiple files which are loaded).