I am using phpseclib to run commands via SSH on another server. I am currently using the Interactive Shell example (See Here)
If I want to send a command, I use $ssh->write("ls -la\n"); and then I run $ansi->appendString($ssh->read()); echo $ansi->getScreen(); to see the screen output.
Is there a way for me to run commands from a form where can I use it like a web-based console?
Yes why not! Then you have to implement a form and send the command to your server. But there is a much easier way. Perhaps with ajax and fetch the return from your command line.
http://www.web-console.org/
There are a lot of projects doing exact that. When you build that on your own you have to look at security and much more.
Related
Supposed to Open SHELL App (C) which i Coded as interface for my purpose
I Already know about exec and shel_exec which couldn't be helpful on this.
My Console Application which i had to OPEN on php is interactive shell and batch (Both Modes are available).
I Need to communicate to shell, not just opening and get result (like exec func).
I want to Open My Shell and Send commands to it , which can be Interactive I/O or batch I/O.
Well If No Straight solution found with php built in Function I am going to pass my command as String Parameter to console application
But Straight solutions with php built in library and behavior still would be accepted
I want to extend the automation of the PacketETH program CLI using PHP
It can be done in GUI however this still means a user has to do it
Is it possible to have the packetETH run and a PHP deliver instructions, and then receive results back for manipulation?
In a broader sense, is this type of connection possible at all?
Thankyou
You can access the command line from php by using the Php System Program Execution functions. http://php.net/manual/en/book.exec.php. You can try out the exec function. It lets you execute shell commands.
To run the packeteth program from php you can use a command like the following:
exec("/path/to/packeteth/packETHcli -i lo -m 1 -f packet1.pca");
I am wondering if a PHP script can be executed from a shell command line.
Does a script executed from shell have the exact functionality if executed from the browser? or is there a difference in coding.
Is it better to run a script from shell for performance and also is it better to run it from windows or unix/linux
I am asking all these questions because, I am suppose to develop a PHP script that can fetch some data from http headers of some urls listed in a MySQL db and then store the data in the database.
Can you guys point me to the right direction please, Do I need ubuntu, or is there a shell that can run php from windows? all I have at the moment installed is WAMP, which has mysql, php and apache server.
I am sorry for being a novice.
thanks for your kind help
I am wondering if a PHP script can be executed from a shell command line.
Yes
Does a script executed from shell have the exact functionality if executed from the browser? or is there a difference in coding.
It won't have $_REQUEST and friends populated, and $_SERVER won't have server information in it.
Is it better to run a script from shell for performance
Maybe. It avoids the overhead of runnning a webserver. It stops you having cached versions in memory for faster re-execution.
and also is it better to run it from windows or unix/linux
Benchmark it.
I am asking all these questions because, I am suppose to develop a PHP script that can fetch some data from http headers of some urls listed in a MySQL db and then store the data in the database.
There doesn't seem to be any need to involve a web server for that.
Can you guys point me to the right direction please, Do I need ubuntu, or is there a shell that can run php from windows?
The standard Windows shell can.
all I have at the moment installed is WAMP, which has mysql, php and apache server.
You'll need the command line version of PHP. I've no idea if WAMP includes it or not.
I am wondering if a PHP script can be executed from a shell command line.
It's possible either by executing:
$ php -f your_script.php
Or by inserting #/usr/bin/env php into the first line of the script and by making it executable.
$ head -n 1 your_sript.php
#/usr/bin/env php
$ chmod +x your_script.php
$ ./your_script.php
Note: this example only works on UNIX systems.
Does a script executed from shell have the exact functionality if executed from the browser? or is there a difference in coding.
You can use the same Syntax/Functions etc. The only difference is that there are command line arguments in $argv and some other values in the $_SERVER variable.
Is it better to run a script from shell for performance and also is it better to run it from windows or unix/linux.
That doesn't really matter. For your usecase you don't really need a webserver, and a full featured GUI. The advantage of having a command line tool is, you can combine your program with other program available like grep etc.
Can you guys point me to the right direction please, Do I need ubuntu, or is there a shell that can run php from windows?
You don't need ubuntu, you can also execute a shell script from windows. The PHP executable is located in the %PATH%. This question will help you in order to do this: https://superuser.com/questions/284342/what-are-path-and-other-environment-variables-and-how-can-i-set-or-use-them
Then simply open cmd.exe and execute a script using php -f your_script.php
Yes, PHP can be run from command line.
No, there aren't any differences in coding.
The only difference is that it's not Apache running the script, but the user you are currently logged in as. That could mean different privileges on certain maps and folders.
Yes you can execute PHP from the command line using:
/path/to/php.exe /path/to/script.php
The main difference is that it doesn't run through Apache, so you won't have things that rely on it (like some $_SERVER data).
Also it won't be subject to timeouts on the command line, unless you have a PHP limit set.
Take a look at http://php.net/manual/en/features.commandline.php for more info.
I want to read in a password as part of a command-line script, but do not what the typed password to appear on the screen. This seems to be a fairly common feature in command-line apps, but my Google-fu has failed in identifying how this works. Is it a feature of the OS? Do you have to intercept the input stream somehow so it doesn't write out to the console? I would like to use this in a php command line script, but I cannot use what I cannot understand.
Some independent searching yielded this link, where way down at the bottom they mention that mysqladmin does not use STDIN to read in the password. How do they do it then, and how could I implement this functionality?
Answering in case someone finds this googling.
It isn't possible in pure PHP. The solution is to execute a small shell script for Linux or a small program for Windows.
The shell script would look like this for the zsh shell:
/usr/bin/env zsh -c 'stty -echo; read -r mypassword; stty echo; echo $mypassword'
A full working implementation was written by Seldaek from Composer, which you can find at https://github.com/Seldaek/cli-prompt
How do you start the Interactive Console for ruby and php
For ruby, you want the 'irb' command.
For python, you can enter interactive mode with the 'python' command.
For php, you enter a basic interactive mode with 'php -a'. Because of its limitations, other interactive shells have sprung up. PHP-Shell is one of them.
Also, if you are working with a Ruby On Rails project you could use
ruby script/console
from your Rails application root. This is a good approach since you get an interactive ruby shell and the advantage is that loads the entire application stack for you. Pretty handy if you are testing your new code or trying to debug something.
php doesn't lend itself very well to an interactive shell, because you can't redefine functions and classes. So while there is an interactive shell available, it's not very useful.
Make sure you have php5-cli installed and type 'php -a' at the command line.
you are looking for phpsh same as irb for ruby. php-cli allow you to run scripts for the command line like
myserver> php -r "echo 'hola mundo';"
so what you are asking and all replies about php-cli are different. also php-cli has it own php.ini that allow you to have differents configurations depends of run php over httpd (like apache) or in bash
saludos
There is an excellent script for PHP that allows you to run a php console on a local website.
http://seld.be/notes/php-console-in-your-browser
There's obvious security implications here, but if it's only accessible locally, then there's no need to worry.
Really saves time if you want to double check the function behaviour, or to isolate a piece of code and diagnose what happens.
For a console with a rails 3.x+ project loaded
rails c
this is shorthand for ruby scripts/rails console
See more abbreviations here: http://xyzpub.com/en/ruby-on-rails/3.2/abkuerzungen.html
In php its php or php-cli - different name in different installations