Php artisan command Run out memory with 32Gb of RAM - php

I have in DigitalOcean a droplet of 32Gb ram with 12 CPU (resize for occasion)
I run php artisan command (laravel 4.2) which never ran. What could be happening?
And the error message after more than 10 minutes:

I answer my own question, with the help of #aynber and #MartinBarker
I solved the problem droping the current database, updating composer (composer update in my local and pushing composer.lock which contain the updates to the server, in the server run composer install with sudo (is not recommendable use sudo with composer.) and runing sudo php artisan.

then edit the php.ini file and increase your memory limit

Related

Unable to run Laravel Composer Update - RAM and Swap file limitation - VPS

I recently subscribed to hostinger vps with 1GB ram. But i cannot run composer update.
[ErrorException]
proc_open(): fork failed - Cannot allocate memory
The problem is i cannot run composer update because of the RAM limitation. I tried setting the ram limit to 512m to 768m to -1 but it still doesnt work. I still get the RAM error Issue.
php -d memory_limit=512M /usr/local/bin/composer update
php -d memory_limit=768M /usr/local/bin/composer update
php -d memory_limit=-1 /usr/local/bin/composer update
I also tried the swap file but unfortunately, hostinger doesn't allow swap files. i cannot use the swapon command.
swapon: /swapfile: swapon failed: Operation not permitted
I am looking for help on the options so that I can run a laravel project on the vps with 1GB ram.
I tried all the suggestions on the docs but none helped.
https://getcomposer.org/doc/articles/troubleshooting.md#proc-open-fork-failed-errors
I am really in a bind here. Any help is greatly appreciated.
As pointed out by #apokryfos , running
composer update
on the development machine then committing the updated composer.lock file and then running
composer install
on the live server resolved the problem.
Thanks to all who answered.

laravel php 7 consumes ram

-short version : When I run "php artisan serve " computer freezes and needs a restart."php 7" using all the ram.what should I do?
-detailed explanation : I created a project with Laravel and put in a lot of work and it worked fine till yesterday ,today I've changed a few lines on some views (no config files were touched) and when I ran "php artisan serve" and opened browser to see the changes my computer got slow and eventually froze completely .I've checked my system resources and saw "php 7" was consuming all of my ram and swap and browser couldn't load the page.
I've checked and my other projects work fine.the problem occures only on this one.
I have HPprobook and 4GiB ram ,10GiB swap memory,using Laravel 5.4 and PHP7 .My OS is a freshly installed Ubuntu 17.4 and using apache 2 as a web server.
I've restarted apache2 ,updated composer packages,dumped autoload but as I expected no effect.
Any one has any idea why this happens?
If you want small ram footprint instead of using php artisan serve You can install valet for ubuntu
P.S php artisan serve does not need apache you can try to stop it

Composer update memory limit

I need to run composer update at my hosting so I log in with ssh and try to run the following command inside /www folder where I have Laravel and composer installation:
composer update
I get this error:
I'm in contact with my hosting provider, they told me to run the command:
php -d memory_limit=512M composer update
I ran this command but I got: "Could not open file: composer"
What to do? What is the solution here?
Set it to use as much memory as it wants with:
COMPOSER_MEMORY_LIMIT=-1 composer update
When you run composer update, the OS will look into the configured paths and try to locate an executable file with that name.
When running php composer update, the composer string is treated as a parameter to PHP, which is not searched in any paths. You have to provide the full path in order to run it.
Running which composer will tell you where the OS finds the composer executable, and then you simply use the full path in the PHP command:
$>which composer
/usr/local/bin/composer
$>php -d memory_limit=512M /usr/local/bin/composer update
...
Note that 512MB might be too few. My perception is that it will happily take 1GB or more, depending on the number of dependencies you use and the variety of versions that you theoretically allow, i.e. if you allow Symfony ~2.3, then you make Composer deal with a lot more possible versions compared to using ~2.7.
Also note that running Composer on the production machine is not the best idea. You would have to have access to Github, maybe provide access credentials, have VCS tools installed, and you will easily break your site if any of the remote hosting servers is offline during your update. It is a better idea to use Composer on a deployment system that does all the preparation, and then moves all the files onto the production server.
Update
It's the year 2020 now, and the way Composer manages its memory has changed quite a bit. The most important thing is that Composer will increase the memory limit by itself if it encounters a limit set too low. This however immediately triggers the problem of running out of memory on machines that have too few memory installed. You can make Composer use less memory by setting the environment variable like COMPOSER_MEMORY_LIMIT=512M, but this will create problems if Composer would need more memory to correctly operate.
My main point remains true: Do not run Composer on machines that have too few memory installed. You potentially need 1.5 GB of free memory to be able to update everything.
The best solution for me is
COMPOSER_MEMORY_LIMIT=-1 composer require <package-name>
mentioned by #realtebo
I am facing problems with composer because it consumes all the available memory, and then, the process get killed ( actualy, the output message is "Killed")
So, I was looking for a solution to limit composer memory usage.
I tried ( from #Sven answers )
$ php -d memory_limit=512M /usr/local/bin/composer update
But it didn't work because
"Composer internally increases the memory_limit to 1.5G."
-> Thats from composer oficial website.
Then I found a command that works :
$ COMPOSER_MEMORY_LIMIT=512M php composer.phar update
Althought, in my case 512mb is not enough !
Source : https://www.agileana.com/blog/composer-memory-limit-troubleshooting/
I had to combine COMPOSER_MEMORY_LIMIT and memory_limit in the command line:
On Windows:
set COMPOSER_MEMORY_LIMIT=99999999999&& php -d memory_limit=-1 composer.phar update
On Linux:
export COMPOSER_MEMORY_LIMIT=99999999999 && php -d memory_limit=-1 composer.phar update
If there's enough memory composer would internally consume it and run without any problem. No need to specifically tell the composer to do it.
Have you tried to increase your swap memory, coz it worked for me. I increased the swap memory to 4096Mb (4GB) and now it all looks great to me.
first use "sudo free" to see available memory and swap memory. and configure swap as,
For Debian:
sudo fallocate -l 4G /swapfile
sudo dd if=/dev/zero of=/swapfile bs=4096k count=1048
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile
to make it permenant add this to /etc/fstab file, /swapfile swap swap defaults 0 0
For CentOS :
[root#myserver]:/# cd /var
[root#myserver]:/var# touch swap.img
[root#myserver]:/var# chmod 600 swap.img
[root#myserver]:/var# mkswap /var/swap.img
[root#myserver]:/var# dd if=/dev/zero of=/var/swap.img bs=4096k count=1000
[root#myserver]:/var# mkswap /var/swap.img
[root#myserver]:/var# swapon /var/swap.img
you can increase your swap memory by changin bs= 1024k or 2048k or 8096k
depending on your physical volume size.
use 'swapon' and swapoff commands to see the difference.
check 'swappiness' (60 should do good,)
cat /proc/sys/vm/swappiness
You can change the memory_limit value in your php.ini
Try increasing the limit in your php.ini file
Use -1 for unlimited or define an explicit value like 2G
memory_limit = -1
Note: Composer internally increases the memory_limit to 1.5G.
Read the documentation getcomposer.org
I made this on Windows 10 and worked with me:
php -d memory_limit=-1 C:/ProgramData/ComposerSetup/bin/composer.phar update
You can change xx Value that you want
memory_limit=XX
On MAC OS High Siera I ran the below:
MacBook-Pro:asiu jack$ php --ini
Returned:
Configuration File (php.ini) Path: /usr/local/etc/php/7.4
Loaded Configuration File: /usr/local/etc/php/7.4/php.ini
Scan for additional .ini files in: /usr/local/etc/php/7.4/conf.d
Additional .ini files parsed: /usr/local/etc/php/7.4/conf.d/ext-
opcache.ini,
/usr/local/etc/php/7.4/conf.d/php-memory-limits.ini
All answers above are setting the loaded config which does update, but notice additional .ini files parsed has php-memory-limits.ini as a separate file. You have to update this file memeory limit as well. same way open in text editor and change to somehting like 2G. The output on memory limit failure should tell you how much memory it needs to run, just set it to higher than that or -1 for unlimited.
COMPOSER_MEMORY_LIMIT=-1 composer update --ignore-platform-reqs
This error can occur especially when you are updating large libraries or libraries with a lot of dependencies. Composer can be quite memory hungry.
Be sure that your composer itself is updated to the latest version:
php composer.phar --self-update
You can increase the memory limit for composer temporarily by adding the composer memory limit environment variable:
COMPOSER_MEMORY_LIMIT=128MB php composer.phar update
Use the format “128M” for megabyte or “2G” for gigabyte. You can use the value “-1” to ignore the memory limit completely.
Another way would be to increase the PHP memory limit:
php -d memory_limit=512M composer.phar update ...
<C:\>set COMPOSER_MEMORY_LIMIT=-1
<C:\>composer install exhausted/packages
For Laravel
Step 1. Open your terminal
step 2. cd into your laravel directory
step 3. Type the command which composer, in your laravel directory and note the directory in which composer resides.
step 4. run the command php -d memory_limit=-1 /opt/cpanel/bin/composer update (you can also run the code if it works for you)
(change /opt/cpanel/bin/composer to the directory path returned in step 3 )
Problem solved
How large is your aws server? If it only has 1gb of ram, setting the memory limit of 2gb in php.ini won't help.
If you can't/don't want to also increase the server side to get more RAM available, you can enable SWAP as well.
See here for how to enable swap. It enables 4gb, although I typically only do 1GB myself.
Source: Got from laracast site
I'm running Laravel 6 with Homestead and also ran into this problem. As suggested here in the other answers you can prefix COMPOSER_MEMORY_LIMIT=-1 to a single command and run the command normally. If you'd like to update your PHP config to always allow unlimited memory follow these steps.
vagrant up
vagrant ssh
php --version # 7.4
php --ini # Shows path to the php.ini file that's loaded
cd /etc/php/7.4/cli # your PHP version. Each PHP version has a folder
sudo vi php.ini
Add memory_limit=-1 to your php.ini file. If you're having trouble using Vim or making edits to the php.ini file check this answer about how to edit the php.ini file with Vim. The file should look something like this:
; Maximum amount of memory a script may consume
; http://php.net/memory-limit
memory_limit = -1
Note that this could eat up infinite amount of memory on your machine. Probably not a good idea for production lol. With Laravel Valet had to follow this article and update the memory value here:
sudo vi /usr/local/etc/php/7.4/conf.d/php-memory-limits.ini
Then restart the server with Valet:
valet restart
This answer was also helpful for changing the config with Laravel Valet on Mac so the changes take effect.
For those who use Laravel Homestead
Write this on Homestead.yaml
variables:
- key: COMPOSER_MEMORY_LIMIT
value: -1
In my case none of the answers helped. Finally it turned out, that changing to a 64 bit version of PHP (M$ Windows) fixed the problem immediately. I did not change any settings - it just worked.
Go to your php ini file
set memory_limit = -1
In Windows 10 (Git bash), i had to use this
php -d memory_limit=-1 C:\\composer\\composer.phar install
Its fixed in later composer versions.
On Windows I had to uninstall composer then download+install latest version https://getcomposer.org/download/
Now running composer update works!
First of all, try to update composer:
composer self-update
For some reason composer v1.0 doesn't works fine, in my case I had to update composer, after that I can execute:
composer update
In my case it needed higher permissions along with this memory limit increase.
sudo COMPOSER_MEMORY_LIMIT=2G php /opt/bitnami/php/bin/composer.phar update

beanstalkd default wal directory

We are using Laravel with BeansTalkD for queuing in our app. Now I am stuck at a point that this command :
php artisan queue:listen
keeps getting jobs, in other words there are a lot of jobs and I have no idea how to clean the queue.
And the problem is that I ran the beanstalkd using this command:
beanstalkd -z 1024*1024
which does not specify wal directory.
I have been searching for the whole last week on how to clean beanstalk work queue, but found nothing.
Tips
I am running this on Mac OS X Yosemite.
Restarting BeansTalkD service did not solve it
I don't store jobs in DB so flush command is not the one. (I don't know if Laravel does that with me knowing but I don't think so)
I am deleting the jobs when I am done but the app generates a lot of jobs.
If you didn't use -b option then restarting beanstalkd (again without -b) should help.
Now if restarting for some reason doesn't work for you and you're using Laravel 5.x you can consider installing artisan-beans package and use php artisan beans:purge command to clean up your queue.
UPDATE: Since you're on Laravel 4.2 you can
install dependency-free CLI tool beanstool. Here's how install v2.0 on OS X
wget https://github.com/tyba/beanstool/releases/download/v0.2.0/beanstool_v0.2.0_darwin_amd64.tar.gz
tar -xvzf beanstool_v0.2.0_darwin_amd64.tar.gz
cp beanstool_v0.2.0_darwin_amd64/beanstool /usr/local/bin/
and then run this in bash
for i in {1..N}; do beanstool delete -t default --state=ready; done
Change N to the number of jobs you want to delete at once and default to the name of your queue (tube).
If you wonder how many jobs you currently have in the queue run
beanstool stats
Beside the accepted answer I found another solution which is to stop (CTRL+C) the command:
beanstalkd -z 1048576
and start a the command again with the -b option:
beanstalkd -z 1048576 -b ~/btd_data
this also solved the problem

Composer killed while updating

I got a problem, I tried to install a new package to my Laravel 4 project.
But when I run php composer.phar update I get this:
Loading composer repositories with package information
Updating dependencies (including require-dev)
Killed
I have looked for the problem in the Internet and saw that the memory is the problem, I think I don't have enough RAM available, I've checked this I have about 411mb free.
Does composer really need more RAM?
The "Killed" message usually means your process consumed too much memory, so you may simply need to add more memory to your system if possible. At the time of writing this answer, I've had to increase my virtual machine's memory to at least 768MB in order to get composer update to work in some situations.
However, if you're doing this on a live server, you shouldn't be using composer update at all. What you should instead do is:
Run composer update in a local environment (such as directly on your physical laptop/desktop, or a docker container/VM running on your laptop/desktop) where memory limitations shouldn't be as severe.
Upload or git push the composer.lock file.
Run composer install on the live server.
composer install will then read from the .lock file, fetching the exact same versions every time rather than finding the latest versions of every package. This makes your app less likely to break, and composer uses less memory.
Read more here: https://getcomposer.org/doc/01-basic-usage.md#installing-with-composer-lock
Alternatively, you can upload the entire vendor directory to the server, bypassing the need to run composer install at all, but then you should run composer dump-autoload --optimize.
If like me, you are using some micro VM lacking of memory, creating a swap file does the trick:
#Check free memory before
free -m
mkdir -p /var/_swap_
cd /var/_swap_
#Here, 2G ~ 2GB of swap memory. Feel free to add MORE
sudo fallocate -l 2G swapfile
chmod 600 swapfile
mkswap swapfile
swapon swapfile
#Automatically mount this swap partition at startup
echo "/var/_swap_/swapfile none swap sw 0 0" >> /etc/fstab
#Check free memory after
free -m
As several comments pointed out, don't forget to add sudo if you don't work as root.
btw, feel free to select another location/filename/size for the file.
/var is probably not the best place, but I don't know which place would be, and rarely care since tiny servers are mostly used for testing purposes.
Unfortuantely composer requires a lot of RAM & processing power. Here are a few things that I did, which combined, made the process bearable. This was on my cloud playpen env.
You may be simply running out of RAM. Enable swap: https://www.digitalocean.com/community/search?q=add+swap (note: I think best practice is to add a seperate partition. Digitalocean's guide is appropriate for their environment)
service mysql stop (kill your DB/mem-hog services to free some RAM - don't forget to start it again!)
use a secondary terminal session running top to watch memory/swap consumption until process is complete.
composer.phar update --prefer-dist -vvv (verbose output [still hangs at some points when working] and use distro zip files). Maybe try a --dry-run too?
Composer is apparently know to run slower in older versions of PHP (e.g. 5.3x). It was still slow in 5.5.9 for me...
DigitalOcean fix that does not require extra memory - activating swap, here is an example for 1gb:
in terminal run below
/bin/dd if=/dev/zero of=/var/swap.1 bs=1M count=1024
/sbin/mkswap /var/swap.1
sudo /sbin/swapon /var/swap.1
The above solution will work until the next reboot, after that the swap would have to be reactivated. To persist it between the reboots add the swap file to fstab:
sudo nano /etc/fstab
open the above file add add below line to the file
/var/swap.1 swap swap sw 0 0
now restart the server. Composer require works fine.
I've got this error when I ran composer install inside my PHP DOCKER container,
It's a memory issue.
Solved by increasing SWAP memory in DOCKER PREFERENCES from 512MB to 1.5GB
To do that:
Docker -> Preferences -> Rousources
Increase the memory limit for composer
php -d memory_limit=4G /usr/local/bin/composer update
Run composer self-update and composer clearcache
remove vendor and composer.lock
restart your local environment and then run
php -d memory_limit=-1 /usr/local/bin/composer install
If you're using docker you can use COMPOSER_PROCESS_TIMEOUT
environment:
COMPOSER_MEMORY_LIMIT: -1
COMPOSER_PROCESS_TIMEOUT: 2000 #seconds
Also in big projects composer needs more RAM than 2GB, you can check that with ps -aux while it is running.
You will have to add it manually inside docker options, nothing else will help.
Here's how I succeeded in installing maatwebsite\excel package from composer in Laravel Framework:
I download composer.json file and composer.lock file from my remote server.
I run composer update from local command prompt (then wait until all the install process finished).
Upload composer.lock file to remote server.
run composer install on remote server (then wait until all process finished).
DONE
composer 2 update have reduced the memory usage
composer self-update
composer update
composer require xxx
Fix for AWS ec2 Ubuntu Server Php Memory Value Upgrade For Magento 2.3.X
Php 7.2 / 7.3
nginx
ubuntu
composer 1.X
mariaDB
magento 2.3.X
Error : Updating dependencies (including require-dev)
Killed
for
Ram Must at least 4GB
Change instance type to suitable or Upgrade Ram
Php Memory Value change
Server Restart
Try to install the same package again
PHP value update
may locate under '/etc/php/7.2/fpm/php.ini'
depend on your server and PHP fpm X.XX version
Using Seed command 'change as your server requires'
on my case >> /etc/php/7.2/fpm/php.ini
memory limit type as "3.5G" or "3500MB"
Php 7.2.X
sudo sed -i "s/memory_limit = .*/memory_limit = 3.5G/" /etc/php/7.2/fpm/php.ini
Php 7.3.X
sudo sed -i "s/memory_limit = .*/memory_limit = 3.5G/" /etc/php/7.3/fpm/php.ini
Test if applied on 'free -h' command
free -h
Install-Package Again#
Install extension via Composer
go to your Magento 2 installation directory
cd /var/www/html/
with 'superuser' privileges
sudo su
Start installation
composer require XXXXXX/XXXXXXX
Enable Module s
php bin/magento module:enable XXXXXX/XXXXXXX
php bin/magento setup:upgrade
php bin/magento setup:di:compile
php bin/magento setup:static-content:deploy
Restart
sudo reboot
Enjioy
I was facing this same issue on my ec2 instance, following steps worked for me :
Copied composer.lock file from my local environment to ec2.
then run sudo composer install and its simply installed all the dependencies for my project.
I solved it maintaining the below steps in my ubuntu server. Hope it will works for you.
Stop my apache server
sudo service apache2 stop
Run composer update
sudo composer update
Start my apache server
sudo service apache2 start
php -d memory_limit=5G composer.phar update
I get this problem caused for a package that don't update correctly with wildcards, I use directly the last version and it works finally.
"l3/cas-bundle": "~1.0" -------> "l3/cas-bundle": "1.1.13"
Solved on Laravel/Homestead (Vagrant Windows)
Edit Homestead.yaml and increase memory from 2048 to 4096
vagrant up
vagrant ssh
Install Symfony with this line on the folder you choose (must be without files)
COMPOSER_MEMORY_LIMIT=-1 composer create-project symfony/website-skeleton . -s dev
I was using:
Virtualbox
4096 Gb RAM
2 CPU
10 GB HDD (500 MB swap)
Ubuntu 20.04
Running:
composer update in a laravel 8 project folder
I didn't set the swap for the virtual machine, so Virtualbox created a 500Mb swap space, which was NOT enough.
So composer was using 4Gb of RAM plus swap.
I gave more swap space to the VM and then it worked.
As the picture below, composer used all my RAM + 2GB of swap
System Monitor
You can try setting preferred-install to "dist" in Composer config.
I was getting this error in a local Docker environment. I solved it by simply restarting Docker.

Categories