views:

155

answers:

2

Situation:

I am writing a program in C that maintains a number of threads. Once a thread ends, a new one is created.

Each thread forks - the child runs a PHP process via exec() and the parent waits for it to finish.

Each PHP process takes the next item from a queue, processes it and exits.

Basic code: http://www.4pmp.com/2010/03/multitasking-php-in-parallel/

Problem:

The PHP processes are Symfony tasks and Symfony requires a fairly huge amount of memory. How can I safely calculate the required stack space for each thread so that PHP processes will have enough memory?

The memory limit set in php.ini is 128Mb so should I allocate this much space in the stack?

+3  A: 

When you fork you get a new process, when you exec the process is replaced by the one you execute. So any setting of stack space in the C program are irrelevant with regards to PHP memory usage.

Douglas Leeder
Sure - but doesn't it inherit the allocated stack space?
SlappyTheFish
Ok, it doesn't - you're right: http://www.opengroup.org/onlinepubs/000095399/functions/exec.html
SlappyTheFish
A: 

In one way YES.. because, since the PHP.ini is restricting the memory usage/limit to 128 MB, we know that it is the max memory the PHP process is going to use. So, its better to allocate such space for each thread [ safe side.. double the size of it ].

Roopesh Majeti