Loading ...
Sorry, an error occurred while loading the content.

Re: [soaplite] Sending return value to soap client without returning from sub { ... }

Expand Messages
  • Georg Grabler
    I recommend you to also take care of the zombies in your father code. If the parent exits (before the child did), you would produce ghosts processes. Write a
    Message 1 of 3 , Dec 25, 2006
    • 0 Attachment
      I recommend you to also take care of the zombies in your father code.
      If the parent exits (before the child did), you would produce ghosts
      processes.

      Write a method, checking the child after the time consuming stuff exited, to
      catch if your child is a zombie.

      Otherwhise, returning in the client method is pretty fine in this case, as
      already mentioned by Mike.

      In the parent method you could use
      waitpid($child_pid, 0);

      If (for any reason) you are about to spawn more than one process in your code,
      you should think about using POSIX 'WNOHANG'

      use POSIX 'WNOHANG';
      $SIG{CHLD} = sub { while( waitpid(-1,WNOHANG)>0 ) {} };

      Best regards,
      Georg

      On Monday 25 December 2006 19:00, Mike South wrote:
      > Hi,
      >
      > I don't have a lot of experience doing this kind of thing, but here's
      > what I would try first (untested code):
      >
      >
      > my $par = shift;
      >
      > my $child_pid = fork();
      > if ($child_pid) {
      > # this is the parent, we'll just return
      > return;
      > }
      > else {
      > # this is the child, we'll do the hard stuff and then bail
      > doTimeConsumingStuff($par);
      > exit;
      > }
      >
      > On 12/23/06, h_emre_k <kwah@...> wrote:
      > > Hi,
      > >
      > > I wrote a small daemon that receives some index value via SOAP and
      > > does further time consuming things based on the value.
      > >
      > > The SOAP client is supposed not to care if the further actions are
      > > sucessfull and it should not wait for the time consuming part to finish.
      > >
      > > Is there any way to send a SOAP result to the client while still
      > > "staying" in the context of the subroutine/method?
      > >
      > > Right now I have something like this:
      > >
      > > client.pl
      > > ---------
      > > my $soap = SOAP::Lite
      > > -> on_fault(sub{})
      > > -> uri($uri)
      > > -> proxy($proxy);
      > >
      > > my $index = "123";
      > > my $result = $soap->doSomething($index);
      > >
      > > server.pl
      > > ---------
      > > my $daemon = SOAP::Transport::HTTP::Daemon
      > > -> new (LocalAddr => $host, LocalPort => $port, Reuse => 1)
      > > -> dispatch_to('FOO');
      > >
      > > $daemon->handle;
      > >
      > > package FOO;
      > >
      > > sub doSomething {
      > > my $par = shift;
      > > doTimeConsumingStuff($par);
      > > return;
      > > }
      > >
      > > What would be the appropriate way to send a return value to client and
      > > keep processing $par?
      > >
      > > I did some searching in this group and read some messages regarding
      > > asynchronous messaging. It seemed an overkill to me implementing some
      > > kind of task tracking system as I really do not care about the actual
      > > result of doSomething();. Most examples also seem to be using the SOAP
      > > daemon within an Apache context, which is not what I am using.
      > >
      > > I´m kind of lost so any hint will be greatly appreciated :)
      > >
      > > Thanks,
      > >
      > > Emre
    Your message has been successfully submitted and would be delivered to recipients shortly.