0

tempting to make multiple PHP scripts. One will start a program, another will send arguments to the program, and the third will get the current output of the program. This is an ongoing program so I cannot just have one page, as it would be loading forever waiting for the program to complete. How would I start a program (it is a shell using the command: sh run.sh) on one page and continue to access the same session of the program on other pages? to clarify, I am running a server that takes arguments at the command line. by session I mean the same instance of the program.

For example, I visit "start.php", and it runs the command "sh run.sh" from in the /server directory on the server computer. Then I visit "command.php", enter my command, and it submits it to "cmd.php?command=command", which emits the command followed by enter to the running process of run.sh.

Ethan McTague
  • 2,236
  • 3
  • 21
  • 53

1 Answers1

1

To persist a php session at the command line you need to save the php session id viasession_id() when you first create the session than before each session_start() call that follows use session_id() to set the session id to the saved session id than you can carry session variables between multiple script calls at the command line.

Though, depending on what you are doing it would probably be a better idea to use a database like MySQL to persist data between php scripts.

elitechief21
  • 2,964
  • 1
  • 17
  • 15
  • this is not what I mean. I mean I am running a server and I want to interact with it between pages – Ethan McTague Feb 07 '14 at 11:54
  • What exactly do you mean by, `interact with it between pages`? Could you give an example? – elitechief21 Feb 07 '14 at 13:21
  • I mean I have a program on the server computer, which I want to start on one PHP page, and then go to another page to send command-line input to the same instance of the program (the program is a server). – Ethan McTague Feb 09 '14 at 13:59
  • See [this](http://stackoverflow.com/questions/5998126/send-command-to-a-background-process) SO post and related link about named pipes – elitechief21 Feb 10 '14 at 14:00