1

say a php script executes a ruby script in the background each time, php script is run from the browser.

what would be an approach to associate the logged in user on the website, to the running background ruby script ?

this is so the logged in user on the website can get feedback on the running ruby script they executed by visiting a section on the website. the user needs to also be able to terminate this running script.

there are many users or clients that logs in to the site and runs many instances of the ruby script in the background individually.

lativo
  • 35
  • 3

1 Answers1

0

You can provide options to any shell script.
So by running

my_script.rb 42

Where 42 is your user's id, you'll know in that script which user started the script.
In your ruby script you can get that value inside the ARGV array.

You'll also need to write somewhere the scrip't PID (identifiant generated when the script is started and allowing you to kill it). For getting the ruby process's pid, you'll find more informations here.

So in order, you do the following :

  • In your PHP script, you start the ruby process with the user id as an option.
  • In your PHP script, you register the process' pid for later use.
  • In your ruby script, you can now know which user is related to it and act consequently (log it at the appropriate place).
  • When you want to kill the script, you take the pid back and send a kill command with this pid.
Community
  • 1
  • 1
Damien MATHIEU
  • 29,275
  • 12
  • 79
  • 89