CryptiniteDemon
March 24th, 2011, 08:47 PM
So I'm trying to get this script to run other programs in the background while also continuing to run.
Basically it's a server that produces new threads for each connection. There's an API that I use to send text messages, but my only option is to use PHP for that part. So what I do is call this php script from perl. I need the php script to run as a daemon.
However, when I try to run the PHP script using Proc::Daemon, it runs the PHP script, but kills the housing perl script.
Code below for example:
my $server = new IO::Socket::INET(
Localhost => "localhost",
LocalPort => "5555",
Proto => "tcp",
Listen => 2,
Reuse => 1);
while (1)
{
my $client;
do
{
$client = $server->accept();
} until ( defined($client) );
my $thrd = threads->new( \&handleComm, $client,"flf" )->detach();
}
So that makes the new thread. handleComm just parses some strings and then calls functions based on the string. Anyway, it calls the sendAlert function below which calls the php script as a daemon. However, for some reason, when this command is called it just closes out of the whole server.
sub sendAlert
{
($xml, $client, $sqlConn) = @_;
$phone = $xml->{cmdData}->{phone};
my $daemon = Proc::Daemon->new(
work_dir => '/opt/theseBins/',
exec_command => "php -f sendSMS.php $phone",
}
what I want is for this to call the PHP script as a daemon without killing the server.
Basically it's a server that produces new threads for each connection. There's an API that I use to send text messages, but my only option is to use PHP for that part. So what I do is call this php script from perl. I need the php script to run as a daemon.
However, when I try to run the PHP script using Proc::Daemon, it runs the PHP script, but kills the housing perl script.
Code below for example:
my $server = new IO::Socket::INET(
Localhost => "localhost",
LocalPort => "5555",
Proto => "tcp",
Listen => 2,
Reuse => 1);
while (1)
{
my $client;
do
{
$client = $server->accept();
} until ( defined($client) );
my $thrd = threads->new( \&handleComm, $client,"flf" )->detach();
}
So that makes the new thread. handleComm just parses some strings and then calls functions based on the string. Anyway, it calls the sendAlert function below which calls the php script as a daemon. However, for some reason, when this command is called it just closes out of the whole server.
sub sendAlert
{
($xml, $client, $sqlConn) = @_;
$phone = $xml->{cmdData}->{phone};
my $daemon = Proc::Daemon->new(
work_dir => '/opt/theseBins/',
exec_command => "php -f sendSMS.php $phone",
}
what I want is for this to call the PHP script as a daemon without killing the server.