1

I have a webpage which has some input tags which are passed to PHP to validate it and then php creates a command for another Python script to run and command is executed using $output = shell_exec($cmd); The Python script is a Selenium script which gives some output/status of what's going on while it's doing.

My question is that is there any way that I can use PHP to shell_exec the command created and display the output of Python script continuously? I can get all the output after the command is executed and not while the script is executing.

I searched on Google but didn't find any help. I read these answers, but they are not helping me...

Python: how to show results on a web page?

Display python script output to HTML page

How to run python script in webpage

How to continuously display Python output in a Webpage?

I don't want to use Flask or Django because my rest of the code is in PHP.

Coder Amogh
  • 145
  • 1
  • 10
  • 1
    you can try enabling websockets in your python script and catch output of your script through websocket in your php script. – Murali Aug 23 '19 at 09:14
  • You can construct such things setting up a socket based client process forking instead of using `shell_exec()` which _per documentation_ first executes and the returns. Take a look at the `proc_open` function php offers: https://www.php.net/manual/en/function.proc-open.php You will find various examples on the internet for this. – arkascha Aug 23 '19 at 09:15
  • `shell_exec` etc. don't use this method. Just create another *loopback* service for easily manage/cache control. – dsgdfg Aug 23 '19 at 10:08
  • Thank you all for giving various suggestions. Can anyone please give some code? – Coder Amogh Aug 23 '19 at 10:56
  • I am still not able to use proc_open or popen in PHP. Can anyone please help me with the code and how to use the functions? I have not understood anything from the documentation... – Coder Amogh Sep 01 '19 at 07:26

0 Answers0