0

I have a PHP file which calls a console application. I have couple of range sliders as inputs to the console application. When I click the search button in my page it calls the console application and if I change the range slider value within 1 sec and call the exe again the output displayed is the previous output and after a while again the output is changed tp the current output.

I guess this is because the previous console application isn't terminated in the second time so it displays the same output and in a while gives the correct output. How can I solve this problem? How can I terminate the previous execution of exe before calling another exe?

The output of the console application is saved in an array. I tried assigning null to the array before exec but it didn't work. I am using apache server in ubuntu.

Funk Forty Niner
  • 74,450
  • 15
  • 68
  • 141
user1583647
  • 1,227
  • 2
  • 24
  • 48

2 Answers2

0

Assuming you have enough priveleges in the console, you can execute a command to kill the process before the second execution. See http://www.howtogeek.com/howto/ubuntu/kill-a-process-by-process-name-from-ubuntu-command-line/

However, if you are in an environment where multiple users are likely to be running this concurrently you will need to know the process ID of the specific instance you wish to kill.

This post has a good example of how you might do this: http://www.php.net/manual/en/function.exec.php#89716

Hearth
  • 383
  • 1
  • 4
  • 13
0

You can just interrupt AJAX if the next one has been sent.

See How to cancel/abort jQuery AJAX request?

Community
  • 1
  • 1
Michael Sivolobov
  • 12,388
  • 3
  • 43
  • 64
  • how can I interrupt ajax? I have a funtion in the button click which calls the page having the exe function myfunction() { $("#display").html(''); $("#retrieveimageform").ajaxForm( { target: '#display' }).submit(); }; – user1583647 Jun 21 '13 at 06:55
  • I don't know how works `ajaxForm` but if you use `.ajax` native jQuery method this page will help you: http://stackoverflow.com/questions/4551175/how-to-cancel-abort-jquery-ajax-request – Michael Sivolobov Jun 21 '13 at 07:54