in reply to Re: getting a posix daemon and a web server to work together
in thread getting a posix daemon and a web server to work together

I thought about threads in the beginning but my host provider said threads were not being supported on their servers because threads were not safe for most modules or something like that. Is there any way to turn off the daemon commands for the children only? I really need help because I don't want to crash their servers again with my endless loop. why exactly was it ending up in an endless loop? --- skype: hardManHardy ---
...waiting for the world to change...
  • Comment on Re^2: getting a posix daemon and a web server to work together

Replies are listed 'Best First'.
Re^3: getting a posix daemon and a web server to work together
by Hardy (Initiate) on Aug 08, 2007 at 03:56 UTC
    also, what host provider are you using to run your thread daemon on and how much does it cost? I am trying to write a daemon and a web server for turn based multi player games. this is why I need a web server accepting clients (lots of clients) and why I need a daemon to keep the script running at all times.
    Skype: hardManHardy
    ...waiting for the world to change...
      i'm using a root server on which i am free to install whatever i like. costs are at 70 euros per month, with practically no bandwidth limitation.
      --------------------------------
      masses are the opiate for religion.
        thanks for the info about your provider. Do you have any suggestions on how I can fix the code I have? How I can stop it from looping? should I only check for one signal, such as the term signal?
        #!/usr/bin/perl -w -t #load support for strict variables use strict; #load support for sockets use IO::Socket; #load posix support for trapping signals use POSIX(); #load posix support for named pipes use POSIX qw(mkfifo); #start of creating a cross-platform method of determining #the current script path and name use FindBin(); use File::Basename(); use File::Spec::Functions; my $script = File::Basename::basename($0); my $SELF = catfile $FindBin::Bin, $script; #end of creating a cross-platform method of determining #the current script path and name #create a new signal set my $sigset = POSIX::SigSet->new(); #create the action you want performed on terminate signals my $termAction = POSIX::SigAction->new('sigTERM_handler', $sigset, &POSIX::SA_NODEFER); #attach the signal to the action you want performed on terminate signa +ls POSIX::sigaction(&POSIX::SIGTERM, $termAction); . . . #the above would be done for the int, pipe, and hup signals. #start of the sub to run when the terminate signal arrives sub sigTERM_handler { #store the signal sent by the system my $HTPad_signalCaught = shift; #run the handler for all exit signals &HTPad_exitSignalHandler("Terminate", $HTPad_signalCaught); } #end of the sub to run when the terminate signal arrives #start of the handler for all exit signals sub HTPad_exitSignalHandler { #reinstate the passed variables my $HTPad_exitType = shift; my $HTPad_signalCaught = shift; #this daemon handler would also process the int, pipe, and hup signals +. unless (exec($SELF, @ARGV)) { Die "Could not restart the script after a $HTPad_signalCaught signal + was received: $!"; } } #end of the handler for all exit signals #ignore child signals in order to do automatic child reaping $SIG{CHLD} = 'IGNORE'; #enter the web server &HTPad_webSserver(); #start of the web server sub HTPad_webSserver { . . . open a socket . . . #start of the parent server accepting clients while ($HTPad_client = $HTPad_server->accept()) { . . . parent fork() a write process for the client . . . process data from the client . . . #close the write child connection close($HTPad_client); #exit the write child to keep it from accepting new clients exit(1); #should this be 1 or something else? parent fork() a read process for the client . . . process data from the client . . . #send sig term to write child when client closes connection kill ("TERM", $clientWritePID); #close the read child connection close($HTPad_client); #exit the read child to keep it from accepting new clients exit(1); #should this be 1 or something else? } #end of the parent server accepting clients } #end of the web server
        Skype: hardManHardy
        ...waiting for the world to change...