command line interface - Running php code using terminal that needs interaction

I have a monitoring application (nagiosxi) that is deployed on a Linux box and some final settings are carried out via the web browser. For example, if the application is deployed on say,192.168.2.10
and if I point the browser tohttp://192.168.2.10
, it automatically redirects tohttp://192.168.2.10/nagiosxi/install.php
. There are some basic settings like verifying the URL and click next, followed by setting up a password and finally hitting finished set-up.
Now, I trying to see if I can do the same using the php CLI
So, in a terminal I tried,
php -f /usr/local/nagiosxi/html/install.php
but this gives a big stdout and I cannot interactively set anything.
Is there a way to do this? Please note I have zero background in PHP.
Answer
Solution:
The PHP manual may help you solve your problem.
I hope the reference code and source link below will help you.
source : https://www.php.net/manual/en/function.fopen.php
I was working on a console script for win32 and noticed a few things about it. On win32 it appears that you can't re-open the input stream for reading, but rather you have to open it once, and read from there on. Also, i don't know if this is a bug or what but it appears that fgets() reads until the new line anyway. The number of characters returned is ok, but it will not halt reading and return to the script. I don't know of a work around for this right now, but i'll keep working on it.
This is some code to work around the close and re-open of stdin.
<?php
function read($length='255'){
if (!isset($GLOBALS['StdinPointer'])){
$GLOBALS['StdinPointer']=fopen("php://stdin","r");
}
$line=fgets($GLOBALS['StdinPointer'],$length);
return trim($line);
}
echo "Enter your name: ";
$name=read();
echo "Enter your age: ";
$age=read();
echo "Hi $name, Isn't it Great to be $age years old?";
@fclose($StdinPointer);
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: mysqli::real_connect(): (hy000/2002): connection refused
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.