0

I've been working on a CMS for a few years and I actually implemented a jquery-based console in the admin area, where you could do some handy things like enable/disable modules and so on.

I recently fiddled around with drupal and decided to install cygwin along with drush. I tried googling around but figured this might be an unusual question: How does one go about creating a CLI for a php-based CMS? And exactly how does exactly drush worK? I mean, I know that it runs from the command line as a batch script in windows. But how does it interact with PHP and so on?

I do know some basic C# but this shouldn't be very hard once i figure out how this fits together. (php, sql, etc).

Any help is appreciated, thanks in advance :)

Petter Thowsen
  • 1,697
  • 1
  • 19
  • 24

2 Answers2

0

Basically you can write a simple CLI shell with a infinite loop plus a 'exec()' or 'shell_exec()' PHP functions. you should get the user commands and send it to shell_exec() function for execute in a system shell and return the output of that to the user.

i.e:

while(TRUE){

if($input != 'exit') $output=shell_exec($input); else break;

echo $output; }

  • you can add other options and customize this simple loop.
  • you can call external programs with 'exec()' function.
Good man
  • 396
  • 4
  • 12
0

You can run a php cli from the terminal only when you have php compiled with cli support. Additional you need to specify an interpreter and pass the path to the script as argument. But you can also use a shebang #!/path/to/php. A better practise would be to use the env variable and not hardcode the path to php: #!/usr/bin/env php. Read here about it: http://tech.vg.no/2012/02/21/dont-hardcode-php-executable-path-in-shebang/.

Micromega
  • 12,486
  • 7
  • 35
  • 72