Command Line Interface

2011-07-08
2012-09-25
  • Justin Noel

    Justin Noel - 2011-07-08

    The old version of the documents explained about using FatFree in the command
    line environment. The new documents have excluded this.

    FatFree still works from the command line. However, not having this info in
    the documentation means most people will never be aware of it.

     
  • fardhana

    fardhana - 2011-10-19

    Hi, could you tell me, how to use Fat-free in the command line?
    I'm new in this framework, and wanna make cronjob which is call php programm
    written in PHP.

    Thanks,

     
  • Bong Cosca

    Bong Cosca - 2011-10-21

    From the old documentation:

    Fat-Free also works in command line mode. If you want to send your program
    output to the console (instead of the Web browser), you can do the following:-

    /usr/bin/php index.php "/about"
    

    This runs the PHP engine, executes your index.php file (where your
    router/contoller code is located) and simulates a Web browser sending a
    request for the contents of the /about URL.

    Once you press the Enter key, control is transferred to your route handler for
    GET /about, in much the same way it would have responded to a similar request
    from a browser. However, all output is sent to stdout, in this case your
    console.

    This makes it easier to see the actual HTML source - assuming that's your
    program's output - instead of the extra Web browser mouse clicks necessary
    just to see the same source. Working at the command line also gives you access
    to your operating system's output redirection facility:

    /usr/bin/php index.php "/about">output.txt
    

    This saves your program's ouput to the file output.txt, which can
    help you in analyzing minute details you won't always see in your Web browser
    - like say, a buggy extra carriage return generated somewhere in the program
    you're testing.

    Command line mode also allows you to send HTTP GET variables, like:-

    /usr/bin/php index.php "/user?firstname=John&lastname=Doe"

    Fat-Free is smart enough to populate PHP's $_REQUEST and $_GET global
    variables with the corresponding values received from the command line. In
    this case, $_REQUEST will contain the string John and $_REQUEST will be
    assigned the string "Doe". Fat-Free's command line mode only allows HTTP GET
    requests, and you can expect that to be stored in the $_SERVER global. The
    value of $_SERVER is automatically set to the URL you specified, i.e. the
    string enclosed in quotes; in the above example,
    /user?firstname=John&lastName=Doe. Similar to browser mode, your /user
    route handler will be invoked once Fat-Free receives the above-stated URL.

    Command line mode can be particularly useful in program debugging. Not all PHP
    errors can be intercepted by Fat-Free (or any PHP program). Such errors in the
    E_ERROR, E_PARSE (syntax errors), and E_COMPILE_ERROR categories won't show up
    in your browser. In this situation, Fat-Free's command line mode can help you
    understand the error, without having to search your server's error log,
    because the error message is displayed at the console. This can save you a lot
    of debugging headaches.

    Note: You still get the same level of protection from XSS and code injection
    attacks when using Fat-Free in command line mode.

    You can switch between command line and browser mode anytime. Of course, if
    your PHP script isn't intended to be used as a Web application, but you still
    need an MVC design pattern, Fat-Free's command line mode will certainly be a
    perfect partner.

     

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

JavaScript is required for this form.





No, thanks