Perl running PHP script

Hi Guys,

I have a perl script running as a daemon on my server…


#!/usr/bin/perl
use warnings;
use strict;
use IO::Socket;
use POSIX  'setsid';
my $cmd = $ARGV[0] || ''; 
our $pidfile = "/var/run/$0.pid";
my $pid = check_status(); 
if ($cmd =~ /help/i) { print <<EOF
$0 [command]
possible commands are: 
    help this
    start start script. Will check if started.
    stop stop script.
    status output status (work | stop)
EOF
} elsif ($cmd =~ /stop/i) {
    print "Script is not working\
", exit unless $pid;
    kill 9, -$pid or die $!;
    unlink $pidfile or die $!;
    print "Killed pid $pid\
";
    exit;
} elsif ($cmd =~ /status/i) {
    print $pid ? "Working with pid $pid\
" : "Stopped\
";
    exit;
}
print("Script already work with pid $pid\
"), exit if $pid;

#let's daemonize
open STDIN, '/dev/null' or die "Can't read /dev/null: $!";
open STDOUT, '>/dev/null' or die "Can't write to /dev/null: $!";
exit if fork; 
setsid or die "Can't start a new session: $!";
open my $f, '>', $pidfile or die $!;
print $f "$$";
close $f;

$| = 1;
my $port = 7777;
umask 0777;
my $server = IO::Socket ->new(
        Domain => PF_INET,
        LocalPort => $port,
        Proto => 'tcp',
        Listen => SOMAXCONN,
        Reuse => 1,
);
die "Bind failed: $!\
" unless $server;
#tell OS to clean up dead children
$SIG{CHLD} = 'IGNORE';
while(my $connection = $server->accept){
  my $name = $connection->peerhost;
  my $port = $connection->peerport;
  if (my $pid = fork){
     close $connection;
     next; # on to the next connection
   }else{
     # child process - handle connection
     print $connection "You're connected to the server!\
";
      while (<$connection>){
        use HTTP::Date;
        my ($date, $time) = split(" ", HTTP::Date::time2iso());
        my ($hour, $min) = split(":", $time);
        open (my $log, '+>>',"../../logs/$port $date.txt")
     || die "Couldn't open log.txt: $!";
     
        print $log $_;
        close $log;
     }
     $connection->shutdown(SHUT_RDWR);
   }
 }
sub check_status {
    my $pid = 0;
    if (-e $pidfile) {
 open my $f, $pidfile or die $!;
        $pid = <$f>;
        unless ($pid =~ /\\d+/ and kill(0, $pid)) {  
    print "Wrong pid file $pidfile. Removing\
";
    unlink $pidfile or die $!;
    $pid = 0;
        }
    }
    return $pid;
}

this is working perfectly at the moment, it basically takes data recieved and creates a file,

Then i have a cron script that runs every min to process this log file using PHP.

Is it possible to somehow add some code to this script that can call the PHP script once the logfile has been genetrated?

Any help will be greatly apperieated

K-

opens perl manual

use backticks to call PHP just like you do in your cron job:

$output = `/path/to/php /path/to/script.php`