Welcome Guest, Not a member yet? Register   Sign In
CLI - CodeIgniter on the Command Line
#1

[eluser]Phil Sturgeon[/eluser]
Update - 14/12/08: Fixed routing and controller/method picking.

Update - 16/12/08: Added URI library extension to make setting this up easier, and added CLI to AUTO in config.

Update - 17/12/08: Added method chaining, beep() function to cause a system beep and made wait countdown override its own display instead of running across the screen.

Check the Wiki page for getting CLI running on the command line. This topic can be just about the CLI library now.


Have been a bit bored at work lately so decided it was time to finish off the CI implementation of a command line class I was working on a while back.

If you want to give it a try, here it is.

CLI Library
#2

[eluser]Phil Sturgeon[/eluser]
Update - 16/12/08: Edited content of post to show how the config can be set to cli, web or both.

In your config, set one of the following values for uri_protocol.

Code:
$config['uri_protocol']    = "AUTO"; // Work it out!
$config['uri_protocol']    = "CLI"; // Command line only

Or to have it working on web with a specific uri type and command line at the same time, change path info to any of the normal CI uri types.

Code:
$config['uri_protocol']    = isset($_SERVER['REQUEST_URI']) ? 'PATH_INFO' : 'CLI';

Works perfectly, just call the file like this:

Quote:php index.php controller method param1 param2

Now I have the logic down, just need to work out how this is actually useable :p
#3

[eluser]Phil Sturgeon[/eluser]
Nobody interested in playing with this?
#4

[eluser]phpserver[/eluser]
What is the advantage of frameworks that have commandline access over ci that 'do not have a commandline access'?.
#5

[eluser]Phil Sturgeon[/eluser]
It seems have misunderstood the point here phpserver. I made no comparison between frameworks and did not complain about the lack of CI's command line support.

I just made a library to make CI do more, isn't that what most of us here are doing? Smile

If you are wondering how this may be useful (to be honest, im hard pushed to find a practical application) it can be used for easier running of cron-jobs, and could eventually lead to various things like PHP-GTK integration for running Windows and Linux apps on a CI codebase. Tell me that wouldn't be fun!
#6

[eluser]Murodese[/eluser]
This will be seriously useful, thanks.
#7

[eluser]tsan[/eluser]
I think CLI is a useful feature. It is perhaps best used together with normal application. Here is an example where I have used (tradional) PHP-CLI.

On my application (which is not completed yet) a big file is uploaded to server. Only basic checking of filename extension and filesize is done during uploading. File data and user selections are stored to database and then user sees a page that uploading succesful. This is a normal web application.

CLI application - which is running all the time - reads cyclically database to find files that are not processed. When found it starts to process them. It takes about one hour per uploaded files/case. This way we can decouple file uploading and file processing. Also CLI can read database and it is easy to find oldest processed files and delete them from hard disk.
#8

[eluser]Randy Casburn[/eluser]
hey Pyro,

When I get some time I am keenly interested in this capability. I've been writing and deploying desktop apps for a while. My apps are not CLI, but I do use the CLI versions of PHP for various reasons.

One of the key uses is off-line synchonization...

Picture your laptop being unplugged from the network randomly while you're attached to your business CRM on-line (PHP) application...it continues to work without a hitch...you plug your laptop back in to the network and your laptop seemlessly reconnects to your on-line CRM. End user never knows the difference.

Yes...there is a use for your work.

I need time...time in a bottle. ;-)

Randy
#9

[eluser]Phil Sturgeon[/eluser]
I guess it can be used for slipping several PHP requests amongst other commands in a bash shell script or batch file too. One cron job, many things get done.

Is the library itself actually handy or are you guys just happy with the router modification? Any feedback for the library?

If the library is fine, I'll move on to playing around with a GTK library.
#10

[eluser]xwero[/eluser]
I'm not sure why you would want to use CI as a desktop php framework. CI is a web framework. A good example is the upload and validation classes. They are based on server variables where a desktop application is mainly a client application.
The same goes for the output. It is designed to display strings not windows an controls.

I think if you want to use CI for desktop apps is a case of hitting screws with a hammer.




Theme © iAndrew 2016 - Forum software by © MyBB