1

I have a script that can be launched n times at the same time through php-fpm. php-fpm pool is set to run under a certain username and I want to limit the number of processes this username can launch.

ps aux|grep fpm
root     7165  0.0  0.0 849288 27872 ?  Ss 05:47   0:00 php-fpm: master process (/etc/php5/fpm/php-fpm.conf)
myuser   7167  4.6  0.1 872512 77148 ?  S  05:47   0:31 php-fpm: pool myapp  #pool I want to limit
www-data 7172  0.2  0.1 863248 62904 ?  S  05:47   0:01 php-fpm: pool www    #default pool

This is how the process launched through php-fpm looks like:

37192 myuser 20   0  347m  53m  10m S   13  0.1   0:00.38 php -f /var/www/html/myscript.php

It's on Ubuntu. I've set in /etc/security/limits.conf:

myuser   soft    nproc           10
myuser   hard    nproc           10

and also included session required pam_limits.so in /etc/pam.d/common-session-noninteractive but the limits don't apply:

cat /proc/$(ps aux|grep "php -f /var/www/html/myscript"|awk '{print $2}'|head -n1)/limits

Limit                     Soft Limit           Hard Limit           Units
Max processes             385951               385951               processes

If I su as the user, it works:

su -s /bin/bash myuser

ulimit -u
10

What gives?

w00t
  • 1,134
  • 3
  • 16
  • 35

0 Answers0