Need help web developers

In General, this situation:
1. there is a page in php (something like a web interface)
2. there is a program on the server that is launched from the web interface via shell_exec()
3. the program progresses gives some information (for example random numbers one after the other)
4. need as the issuance of these numbers and display them on the page

Actually a question: whether it is possible to organize in php (maybe with the use of JS)?
PS: of course the output need to reload the page a La AJAX
October 8th 19 at 02:23
6 answers
October 8th 19 at 02:25
There is a simple option, there are difficult.
Simple: run the command via proc_open(), read from the open stream command and give to the page using the echo command. After each issue doing a flush() to send the result to the page. The page itself will hang "underutilized", the connection to the server will be opened as the script will be load the new data. Plus is simple, cons constraints on the layout (the simpler the page the better). If the browser, an intermediate proxy server or web server configured to break the open connection after some time, the method will work for very long commands.
More complex variants are associated with AJAX either the same connection to open from JavaScript and uploaded to the results page — so you can make a more complex layout, or make very difficult, we put the result of command execution into a file on the server, write a php-script, which gives parts of it to our JavaScript which displays it on the page.
Exactly what I need, thank You very much! - Emelia.Cummings commented on October 8th 19 at 02:28
First, even with the use of flush content may accumulate in the Buer of the web serer (depends on the used server and its configuration). Secondly, in case of using AJAX is not the fact that JavaScript will be able to read data from an unfinished query. Therefore for a robust implementation, the data must either send some kind of web socket, or separate queries. - antonette.Gislas commented on October 8th 19 at 02:31 - leila56 commented on October 8th 19 at 02:34
October 8th 19 at 02:27
Why passthru to you?

passthru ('--exec somecommand');


The output will go in real-time on the screen
October 8th 19 at 02:29
let the program displays a random number in the file, and ajax this file periodically reads and displays, via a php script if needed.
October 8th 19 at 02:31
With the move come the following thoughts:

1)If I'm not mistaken, when the program is run via shell_exec in PHP, use the program will not work and will not end, will not give the result in PHP, therefore you will get in PHP, the entire array at once.

2) sometimes something like watch tail-n 5 /var/log/syslog.log

3) You may be easier to configure your program to write text file, whose name will give her a PHP script and then PHP script in a loop to read this file
Unfortunately, the problem of predictivemodel program. Given a program and under it we need to write a web wrapper - Emelia.Cummings commented on October 8th 19 at 02:34
dir ./ > c:/1.txt you are not editing the program dir in this case?) - antonette.Gislas commented on October 8th 19 at 02:37
October 8th 19 at 02:33
Maybe I'm doing something wrong, but I have no realtime...(
$result = passthru('bash /etc/startup/');

echo 10
sleep 3
echo 5
sleep 4
echo 5
Hmm. Here, apparently, the problem is output buffering in Apache (under cli everything works), is it possible to disable buffering in Apache on the page — I don't know... - Emelia.Cummings commented on October 8th 19 at 02:36
October 8th 19 at 02:35
In General, system('bash /etc/startup/') does what you need, but as mentioned above there are nuances with the configuration of the web servers. For example if you have nginx in front of apache+mod_php, the behavior to predict Novozymes.

Find more questions by tags Computer networksPHPJavaScript