php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #18775 Conflict with variables between father and child
Submitted: 2002-08-07 05:40 UTC Modified: 2002-08-24 00:00 UTC
From: bariou at brasnah dot com Assigned:
Status: Not a bug Package: POSIX related
PHP Version: 4.2.2 OS: Linux
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: bariou at brasnah dot com
New email:
PHP Version: OS:

 

 [2002-08-07 05:40 UTC] bariou at brasnah dot com
I work with the pcntl extension and sockets, and I'm working on the developpement of a multiuser server. Several clients can connect limited to FD_SIZE. I start by a setup : 

//Setup of the sockets
....
//Setup of the client array
$i=0;
 while($i<FD_SETSIZE){
     $client[$i]=null;
     $i++;
 }

while(1){
 Here the parent cheks connection
  $new_socket=socket_accept(main_socket);
 It accepts and puts the new socket ressource in the first free slot of the array client 
....
   $client[$k]=$new_socket
.....
   if(!pcntl_fork){
      Child here.....
      Manage the dialog  its OK ! with several connection
      ....
      but when I shutdown a connection, exit is correct 
      ... I need to remove the linked ressources from
      $client[$slot] and it is the same for the select 
      array...
      So I do $client[$slot]=null;
      .... But It seems to fail, and each time the parent
      continues   to see the allocate ressources, so it
      refuses more connexion, because $client[$slot] is 
      not change from the parent point of view.
     }//En child
   }//
Where I'm wrong, is there a bug for variables between parent and child ? Or maybe I make a confusion for the way 
to remove ressources from my client array (value or references) ?

So, now I'm lost, Could somebody gives me some help about please ? I can send all the code if necessary !

Thanks for your help

Marcel

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-08-24 00:00 UTC] jason@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

Processes do not share memory, they are completly independant of each other. After the fork, a parent can not modify a childs memory area, and a child can not modify a parent's memory area. You either rethink your design, use shared memory, or use sockets for interprocess communication

-Jason
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Oct 04 22:01:27 2024 UTC