Increasing PHP's memory_limit on Ubuntu 20 not working - php

I'm running a php script via terminal and I get this error message Allowed memory size of 536870912 bytes exhausted.
So i then added ini_set("memory_limit", "4096M"); to the php file and that did not work.
Then i run php --ini to see which loaded cli file (/etc/php/7.4/cli/php.ini) is being used and after editing said file i found that there is no memory limit set in it ini_set("memory_limit", "-1");
I have no idea what's going on (not very linux savvy). Where is it drawing the conclusion that it only has 512M of available memory?
Edit #1: I also did a phpinfo() which said the php.ini file is at /etc/php/7.4/apache2/php.ini so I edited that file as well, still getting the same result (restarted apache and initiated a new terminal window as well)
Edit #2: the script is run by php mylocalphpfile.php -params
Ubuntu 20, php 7.4

Ok found out that the forked script from Github has some references to other dependencies in which the memory_limit is being forced to be 512M.
Removed that line of code form the lib and now it's working.

Related

Can't get PHP to allow memory size larger than 536870912 bytes. Magento Script

I am trying to run a product export with Magento's dataflow using the CLI script found here: https://www.kerstner.at/2015/07/run-magento-data-flow-profile-from-shell/
The issue I am facing is the script always stops with the following error:
Fatal error: Allowed memory size of 536870912 bytes exhausted
I have attempted to change the memory_limit for PHP in multiple places:
Changed all php.ini files
Added "ini_set("memory_limit","1024M");" to the code.
Input "php -d memory_limit=1024M" at the command line.
Checked the setting using the CLI command "php -i | grep
memory_limit"
Checked the memory_limit using phpinfo()
...and yet I cannot get the script to execute beyond 536870912 bytes.
Is there something built into Magneto that would stop this? I am running out of ideas.
My Environment:
OS: Ubuntu Server 16.04
Total/Free Memory: 8GB/6.9GB
PHP 7.0
PHP Settings:
/etc/php/7.0/apache2/php.ini : memory_limit = 1024M
/etc/php/7.0/cli/php.ini : memory_limit = 1024M

Can't run php artisan commands on laravel

I searched everywhere but i really can't find anything. I am trying to run php artisan but it seems that it just doesn't work.
Specifically i run this command when i am connected through ssh :
/opt/cpanel/ea-php71/root/usr/bin/php artisan
It is the same with php artisan but i am choosing a specific php version (7.1.5). This command should normally show up the rest of artisan commands.
The error i get :
PHP Fatal error: Allowed memory size of 2097152 bytes exhausted
(tried to allocate 4096 bytes) in
/home/username/laravel/vendor/composer/autoload_static.php on line
274
My hosting provider tried to increase the memory limit but nothing happened. I tried increasing it a lot through .php files too.
Also i have tried running composer install/update/clear cache/dump autoload.
Please ask for further information if needed,
Any ideas?
Try to check spelling in the php.ini file. That happened to me when I set memory_limit = 512MB (that is false) instead of memory_limit = 512M (wich is correct). For some reason php understood it as 2MB of memory.

laravel artisan command throwed `Allowed memory size of bytes exhausted` error

In my laravel 5.4 project, I can not run php artisan command. An Allowed memory size of 2097152 bytes exhausted error occured. The website can be view properly in the browser, and laravel.log is also empty, but artisan command in the terminal failed,like this:
➜ laravel git:(dev) ✗ php artisan
PHP Fatal error: Allowed memory size of 2097152 bytes exhausted (tried to allocate 4096 bytes) in /var/www/laravel/vendor/symfony/finder/Finder.php on line 120
It seems like the memory is not enough, I set bigger value for memory_limit,like this:
➜ laravel git:(dev) ✗ php -i |grep memory_limit
memory_limit => 2048MB => 2048MB
But it did not work,could anyone help me, please?
I got this type of error as laravel could not connect to Database. In Laravel 5.4, if database is not connected, it take lot of memory. I think, this is the bug in 5.4.
In general, to increase the memory limit, goto terminal and type
"php --ini".
This will show as
$ php --ini
Configuration File (php.ini) Path: /Applications/XAMPP/xamppfiles/etc
Loaded Configuration File: /Applications/XAMPP/xamppfiles/etc/php.ini
Scan for additional .ini files in: (none)
Additional .ini files parsed: (none)
This will show the location of php.ini file in your system.
2) Then open php.ini file in vi search for memory_limit using '/' in command mode. Then edit the line by pressing 'i' and memory_limit=2000:M.
3) press esc and type ":wq" (To save and quit)
Locate your php.ini file by writing php --ini in the console (in my case it is located in /etc/php/7.2/cli/). Open php.ini, locate the line that sets memory_limit, and set it equal to -1 (memory_limit=-1).

PHP memory_limit Won't Increase on CLI

Evening, I am try to run a script that need a lot of memory from the command line.
System is Linux LinuxMint 3.2.0-23-generic w/ PHP Version => 5.3.10-1ubuntu3.6
I have memory_limit -1 in php.ini for CLI and am also setting ini_set( 'memory_limit', '-1' );
but if I run phpinfo() via the command line it says:
memory_limit => 300M => -1
Does anyone have any idea why this is?
I've also tried setting the memory limit via the command on the CLI. No difference.
Thanks for the info, Sammitch, but when I am running scripts I get:
PHP Fatal error: Allowed memory size of 314572800 bytes exhausted (300MB)
It appears this is a system, issue, but I cannot fix it.
EDIT: after searching, I found I had set a memory limit of 300MB in my global config.php file. Be diligent!
You're not understanding the format.
variable_name => default_value => current_value

PHP Extension (memcache|memcached) not showing in phpinfo() but showing in php -m and php -i?

I am getting both modules listed as installed / configured when I use:
php -m
or if I use:
php -i
but when I use:
$m = new Memcache;
// or
$m = new Memcache();
// or
$m = new Memcached();
//or
$m = new Memcached;
I get the following error:
Fatal error: Class 'Memcached' not found
I am running on a Mac - OS X (10.5.7) with default install of apache & php. Additionally, I have memcached running as a daemon on 127.0.0.1:11211 and libmemcache as required by the php-memcached library. I have restarted apache tons of times and even done a machine restart.
Does anyone know why the modules/extensions show up in the command line but not in my phpinfo()? I am literally stumped, after 3 hours of googling, I am just about ready to give up.
Also, please note, my phpinfo() outputs my ini files as follows AND they are both the exact same file:
Configuration File (php.ini) Path: /etc
Loaded Configuration File: /private/etc/php.ini
UPDATE:
Apache is failing to load the extension.
[Fri May 14 04:22:26 2010] [warn]
Init: Session Cache is not configured
[hint: SSLSessionCache] PHP Warning:
PHP Startup: Unable to load dynamic
library
'/usr/lib/php/extensions/no-debug-non-zts-20060613/memcached.so'
- (null) in Unknown on line 0 PHP Warning: PHP Startup: Unable to load
dynamic library
'/usr/lib/php/extensions/no-debug-non-zts-20060613/memcache.so'
- (null) in Unknown on line 0
Does anyone know why or how this would happen? Both of the files referenced above DEFINITELY ARE there. Should I move this question to server fault?
Your webserver is probably using mod_php, which is a seperate bit of code from the standalone (CLI) interpreter. If they are both using the same ini file, and the memcache extension is configured in the ini file, then it sounds like for some reason, the mod_php is failing to load the extension - check your webserver error_log for startup errors.
It may be that the mod_php was compiled without memcache support (most extensions need to have a stub file linked into the php code, even though the bulk of the code is not linked until run time). Or it may be a permissions problem on the shared object file. Or your webserver may be running chroot, and unable to find the extension (which would also mean that although the ini files appear to have the same path, this is relative to different roots).
HTH
C.
because both versions use different php.ini
place your php.ini into location noted in the phpinfo() outout
I would suspect that the issue revolves around permissions. When you run php from comand line, it runs as the user invoking it. When run as an apache module, it runs as "nobody".
I would assume that the memcached.so file, or the directory it's in does not have proper permissions.
I stumpled upon this post and was having the exact same problem with an extension in my php -i but not in phpinfo(). Mine was a permissions problem because of selinux on a CentOS machine. I had to change ownership and permissions and now it is working as expected.
Set php path in environment variables as given below.
Right-click on "My Computer"
Properties
Advanced Tab > Environment Variables
Under System variables, scroll down to find "Path", select and click on Edit.
Add path to your php install on the end (make sure to precede with semi-colon ";"). Example: ";C:\php7"
Click Ok.

Categories