I'm trying to write a script that I can run from my website, which, when the "start" button is pressed, will run another (perl) script autonomously and continuously. I have read about using the php exec command to start another program, and then diverting the output of that program to a file to allow it to return immediately. I am testing it so that the perl script should send out an email every 10 minutes but it doesn't want to work. Can anyone see what is wrong?
This is the "control" page
Code: Select all
<html>
<body>
<form name="start" action="instigate.php" method="POST">
<input type="submit" value="Start" />
</form>
<form name="stop" action="rescind.php" method="POST">
<input type="submit" value="Stop" />
</form>
</body>
</html>Code: Select all
<?php
if (file_exists("lock.txt"))
{
unlink("lock.txt");
}
execInBackground( mail.pl );
function execInBackground($cmd)
{
exec("/home/p/a/paullee_com/tests/" . $cmd . " > /dev/null &");
}
?>
Code: Select all
<?php
$ourFileName = "lock.txt";
$ourFileHandle = fopen($ourFileName, 'w') or die("can't open file");
fclose($ourFileHandle);
?>
Code: Select all
#!/usr/bin/perl
$outfile = "lock.txt";
do
{
my $sendmail = "/usr/bin/sendmail";
open(MAIL, "|$sendmail -oi -t");
print MAIL "From: zak\@zen.com\n";
print MAIL "To: paul\@paullee.com\n";
print MAIL "Subject: $test\n\n";
print MAIL "$Just testing\n";
close(MAIL)
sleep(600);
}while(!(-e $outfile));
Paul