Hi,
Could some of you who know alot about php take a look at the code below and let me know if there are any major problems with it.
What it is meant to do is...
Get the html vars that are submitted to it, in this case PRNO, and then execute the program DUV with the html variables as arguments. DUV then begins doing what it needs to, but in order to free the licence I need to run the process in the background which returns control to the PHP.
I am only meant to return to the client once the background process is complete so I made DUV return a unique filename that the PHP will then wait for, as soon as the file exists, the contents are sent back to the client and the file is deleted.
It works great so far, tested it and I cant see any problems other than minor cleaning up to the code, adding some sort of a log, and removing the counter displays.
<?php
$read_var = $_REQUEST['PRNO'];
$cmd = <<<EOT
cd /dir1/dir2/dir3 ; /dirA/dirB/dirC/dirD/sample_executable "DUV $read_var"
EOT;
$waitFile = '../DUV-bin/'.trim(shell_exec($cmd));
echo "***".$waitFile."***";
$cntr = 0;
while (!(file_exists($waitFile))) {
$cntr++;
echo $cntr;
flush();
ob_flush();
sleep(1);
}
$readFile = fopen($waitFile,'r');
$theData = fread($readFile,filesize($waitFile));
echo $theData;
unlink($waitFile);
?>
I am just worried cause it seemed so simple, maybe I am forgetting something??
Would this handle say 100 connections at the same time? I tested with 10 from my side any it worked fine.
Any comments or suggestions would be appreciated, even criticism. (But be nice, only a few days working with PHP so far.)
Thanks,
Regards,
Damian