Too many pipes open in php-fpm

Configuring php-fpm I had a problem – even when configured in php-fpm.conf

<value name="max_children">150</value>

I got only about 120 childrens.  I found that the problem was krenel maximum open files limit. You can check it with

ulimit -a
core file size (blocks)     unlimited
data seg size (kbytes)      unlimited
file size (blocks)          unlimited
open files                  256
pipe size (512 bytes)       10
stack size (kbytes)         8192
cpu time (seconds)          unlimited
max user processes          29995
virtual memory (kbytes)     unlimited

These values can be globally changed in

/etc/system

. In this case reboot is needed, but for me it was easier  to add

ulimit -n 1024 

at the top

sbin/php-fpm

startup script.

Dynamic library functions’ listing

Sometimes it would be useful to see what functions does export dynamic library.

There is very useful solaris tool which may help

/usr/ccs/bin/nm

example usage:

/usr/ccs/bin/./nm /lib/libmd5.so
/lib/libmd5.so:

[Index]   Value      Size    Type  Bind  Other Shndx   Name

[27]    |         0|       0|SECT |LOCL |0    |1      |
[2]     |       148|       0|SECT |LOCL |0    |1      |
[3]     |       308|       0|SECT |LOCL |0    |2      |
[4]     |       612|       0|SECT |LOCL |0    |3      |
[5]     |       972|       0|SECT |LOCL |0    |4      |
[6]     |      1004|       0|SECT |LOCL |0    |5      |
[7]     |      1060|       0|SECT |LOCL |0    |6      |
[8]     |      1100|       0|SECT |LOCL |0    |7      |
[9]     |      1208|       0|SECT |LOCL |0    |8      |
[10]    |      1268|       0|SECT |LOCL |0    |9      |
[11]    |      5392|       0|SECT |LOCL |0    |10     |
[12]    |      5472|       0|SECT |LOCL |0    |11     |
[13]    |      5600|       0|SECT |LOCL |0    |12     |
[14]    |      5604|       0|SECT |LOCL |0    |13     |
[15]    |     73728|       0|SECT |LOCL |0    |14     |
[16]    |     73740|       0|SECT |LOCL |0    |15     |
[17]    |     73852|       0|SECT |LOCL |0    |16     |
[18]    |     74068|       0|SECT |LOCL |0    |17     |
[19]    |     74108|       0|SECT |LOCL |0    |18     |
[20]    |     74120|       0|SECT |LOCL |0    |19     |
[21]    |     74184|       0|SECT |LOCL |0    |20     |
[22]    |         0|       0|SECT |LOCL |0    |21     |
[23]    |         0|       0|SECT |LOCL |0    |22     |
[24]    |         0|       0|SECT |LOCL |0    |1      |
[25]    |         0|       0|SECT |LOCL |0    |23     |
[26]    |         0|       0|SECT |LOCL |0    |24     |
[43]    |      5304|      88|FUNC |LOCL |0    |9      |Encode
[48]    |      1588|     136|FUNC |GLOB |0    |9      |MD5Final
[52]    |      1268|      60|FUNC |GLOB |0    |9      |MD5Init
[42]    |      1772|    3532|FUNC |LOCL |0    |9      |MD5Transform
[65]    |      1328|     260|FUNC |GLOB |0    |9      |MD5Update
[40]    |     74120|      64|OBJT |LOCL |0    |19     |PADDING
[63]    |         0|       0|OBJT |GLOB |0    |ABS    |SUNW_1.1
[59]    |     73852|       0|OBJT |GLOB |0    |16     |_DYNAMIC
[30]    |     74184|       0|OBJT |LOCL |0    |20     |_END_
[57]    |     73728|       0|OBJT |GLOB |0    |14     |_GLOBAL_OFFSET_TABLE_
[50]    |     73740|       0|OBJT |GLOB |0    |15     |_PROCEDURE_LINKAGE_TABLE_
[28]    |         0|       0|OBJT |LOCL |0    |1      |_START_
[56]    |         0|       0|NOTY |WEAK |0    |UNDEF  |__1cG__CrunVdo_exit_code_in_range6Fpv1_v_
[54]    |         0|       0|NOTY |WEAK |0    |UNDEF  |__1cH__CimplKcplus_fini6F_v_
[58]    |         0|       0|NOTY |WEAK |0    |UNDEF  |__1cH__CimplKcplus_init6F_v_
[35]    |     74112|       0|NOTY |LOCL |0    |18     |_cpp_finidata0
[51]    |     74184|       0|OBJT |GLOB |0    |19     |_edata
[62]    |     74184|       0|OBJT |GLOB |0    |20     |_end
[61]    |      5864|       0|OBJT |GLOB |0    |13     |_etext
[60]    |         0|       0|NOTY |WEAK |0    |UNDEF  |_ex_deregister
[36]    |      5600|       0|NOTY |LOCL |0    |12     |_ex_range0
[46]    |      5600|       0|NOTY |LOCL |0    |12     |_ex_range1
[53]    |         0|       0|NOTY |WEAK |0    |UNDEF  |_ex_register
[34]    |     74084|       0|NOTY |LOCL |0    |17     |_ex_shared0
[45]    |     74100|       0|NOTY |LOCL |0    |17     |_ex_shared1
[37]    |      1268|       0|NOTY |LOCL |0    |9      |_ex_text0
[47]    |      5392|       0|NOTY |LOCL |0    |9      |_ex_text1
[32]    |      5472|     128|FUNC |LOCL |0    |11     |_fini
[29]    |      5392|      80|FUNC |LOCL |0    |10     |_init
[31]    |      5604|       4|OBJT |LOCL |0    |13     |_lib_version
[55]    |         0|       0|FUNC |GLOB |0    |UNDEF  |bcopy
[49]    |         0|       0|FUNC |GLOB |0    |UNDEF  |bzero
[33]    |         0|       0|FILE |LOCL |0    |ABS    |crti.s
[44]    |         0|       0|FILE |LOCL |0    |ABS    |crtn.s
[1]     |         0|       0|FILE |LOCL |0    |ABS    |libmd5.so.1
[39]    |         0|       0|FILE |LOCL |0    |ABS    |md5.c
[64]    |      1724|      48|FUNC |GLOB |0    |9      |md5_calc
[41]    |      5608|     256|OBJT |LOCL |0    |13     |md5_consts
[38]    |         0|       0|FILE |LOCL |0    |ABS    |values-Xa.c</em></blockquote>

Shared libraries conversion

I was wondering if it’s possible to convert binary dynamic library to a shared static library and vice versa.  I’ve done some research and I found a solution to do it but only in one direction.

ar -x libtermcap.a

extracts static library to .o object, then you can compile it to dynamic library

gcc -shared *.o -o libtermcap.so.2

Unfortunately it looks like that conversion in opposite direction is impossible.

php-fpm on Solaris 9 Sparc

If  any one was trying to use php-fpm knows that on Sparc platform have seen: “unsupported processor. please write a patch and send it to me”.

Php-fpm is a great project, so I decided to write my own patch for php 5.2.10 – you can download it here.

Mainly I’ve added necessary assembler code in /sapi/cgi/fpm/fpm_atomic.h for Sparc platform.  Patch also solves issues which I found on my Solaris 9 :

-broken switching between systems with inttypes.h or  stdint.h – I added #if HAVE_INTTYPES_H directives in few places

-if system doesn’t have unsetenv() function it won’t compile – I added #ifndef HAVE_UNSETENV and my implementation of this function in /sapi/cgi/fpm/fpm_env.c if wasn’t in system

-in /sapi/cgi/fpm/fpm_env.c setenv() function wasn’t working properly – on my solaris 9 was adding some stupid data do ENV, I don’t know if it was ok or not on other systems. I’ve rewritten it in other way.

– when /libevent/libevent.a was compiling no proper /libevent/event-config.h was generated. It was a problem when for example system doesn’t have stdint.h – I  added this file in
/libevent/Makefile.in like this “libevent.a: event-config.h $(libevent_a_OBJECTS) $(libevent_a_DEPENDENCIES)”  and changed order in /sapi/cgi/Makefile.frag to: “$(SAPI_CGI_PATH): $(PHP_GLOBAL_OBJS) $(SAPI_EXTRA_DEPS) $(PHP_SAPI_OBJS)

Now as I tested everything compiles and work on Solaris 9 Sparc even in 64bit mode. I’m using it on site with about 250 000 shows per day and for now have no problems. It should be universal for all platforms now! 🙂