Re: pcntl_fork?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Sharing variables between processes and their forks needs something like shmop or systemv shared memory.

Additionally, shared memory only lets you share basic variables and not database resources... or as far as I understand.

So, each fork is required to create its own connection to the database if you want to use it.

Chris wrote:
Hi Peter,

So each thread accesses it's own database connection (ie it'll open $childrencount connections). Is that what you want?

I was trying to get it to share the db connection over the parent and children threads.

(The strange thing is the mysql equivalent of my version works ok - it forks the db connection properly and it's still accessible).
The first SELECT statement in my code, and where you originally had placed your db connection... that would be executed by each fork. You're probably already getting multiple connections in mysql anyway.

This is precisely the reason you want to ensure you close of db connections after you do not need them.

I found that connecting to sql before the if ($pid) statements would make the database resource unusable, which is why I've closed it and reopened it later on in the script.

Hope that helps!

Regards,
Peter Hoskin

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux