Opening a "terminal window" from php

General discussions related to php

Moderators: egami, macek, gesf

Post Reply
KenHorse
New php-forum User
New php-forum User
Posts: 23
Joined: Sat Dec 26, 2015 12:18 pm

Sun Feb 07, 2021 9:23 am

Here's the scenario:

From a php created webpage, I'd like to open some sort of terminal window that runs a python script. My python script includes a progress indicator ("command line" type) and then close the window after the script is finished.

The problem I've seen with calling shell or shellexec from PHP is any output from the called script is not displayed until control is returned to the calling php script, hence why I want to do something like this
simonbrahan
php-forum Fan User
php-forum Fan User
Posts: 90
Joined: Mon Jun 08, 2020 2:00 am
Contact:

Sun Feb 07, 2021 10:06 am

PHP runs on your web server; any animation you display - your progress bar in this case - has to run on the user's web browser. This makes your requirement pretty complicated.

You need an endpoint on your server which the user can call which means "start the process". Call this "start.php". "start.php" has to start the process, then instantly return some process ID that uniquely identifies the user's process. Starting a background process is a whole other box of pain, since PHP is designed to finish processing *then* respond to the request.

You need an endpoint on your server which the user can call which means "check the process". Call this "checkstatus.php". This endpoint will accept the process ID returned above, and return some measurement of how far along the process is.

You need a client side (eg javascript) script that will periodically call "checkstatus.php" and use the response to render a progress bar.

You could also do this using web sockets, but you'd need someone else to show you through that.

All honesty, I'd recommend against trying to give your users real time feedback from a web service.
Post Reply