How would you have done this different?
It gets a directory listing, files are all postscript, converts them to a pdf, prints and deletes them. The script works swimmingly, but I'd like to see what I could have done better. This uses php-cli and is run from cron once a minute.
#!/usr/bin/php
<?php
$directory = "/home/dewarpag/";
#read file(s) into an array
if ($files = opendir($directory)){
#loop through array
#making pdf's and printing them
#until the directory is empty
#as long as they are not younger
#than 30 seconds
while (false !== ($currentFile = readdir($files))){
if ($currentFile != "." && $currentFile != "..") {
#get current time (unix epoch)
$currentTime = date(U);
#get file times (remember, it's epoch)
$fileTime = date(filemtime("$directory$currentFile"));
$remainder = $currentTime - $fileTime;
#IF file is older than 30 seconds
#make it a pdf and print it
if ($remainder > 30){
$currentPDF = $currentFile . ".pdf";
$makePDF = `/usr/bin/ps2pdf $directory$currentFile $directory$currentPDF`;
sleep(4);
print "\nprinting $currentPDF\n";
$print = `lp -dNWSProof $directory$currentPDF`;
$cleanup = unlink("$directory$currentFile");
$cleanup = unlink("$directory$currentPDF");
}//end if
}//end if
}//end while
}//end if
?>