Jump to content

Will this work?


DMeerholz

Recommended Posts

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.