Wednesday, April 1, 2015

Needed Silex Packages

I am just going to throw out a list of packages/service providers I am using and explain why.

This is what my composer.json file looks like:


{
    "authors": [
        {
            "name": "Tim Withers",
            "email": "tim@opticip.com"
        }
    ],
    "require": {
        "silex/silex": "1.2.*",
        "silex/web-profiler":"1.0.*",
        "symfony/yaml": "2.7.*@dev",
        "filp/whoops": "1.1.*",
        "zendframework/zend-soap": "2.3.*@dev",
        "symfony/console": "2.5.*",
        "symfony/config":"v2.2.0",
        "mheap/Silex-Memcache": "@dev",
        "igorw/config-service-provider":"1.2.*"
    },
    "require-dev": {
        "phpunit/phpunit": "4.5.*"
    },
    "autoload": {
        "psr-0": { "TeacherManager": "src/" }
    }
}


Silex

Of course, how can you have a Silex app without Silex.

Silex Web Profiler

This is awesome.  It is actually a Symfony plugin.  I saw it and used it when developing in Symfony and wondered if there was a service provider for it.  Sure enough, there is.

When using the Web Profiler it will only work when you send a response to the browser.  Using "exit()" or returning a string only will not allow the web profiler to work.  You must return a response using Symfony Response or the Silex Application.

Yaml

This is just another way to write config files.  Similar to JSON, but easier as there are no quotes.

Remember, quotes not needed.  Avoid tabs at all costs.

Whoops!

Laravel showed me the greatness of Whoops and Silex has a provider for it.  After configuring it, every error will run through Whoops and display on your screen with incredible amounts of information.  It will provide all the request information, server information, session information, as well a stack trace with the line of code in questions highlighted.  If you haven't used it, use it.  It will make debugging a hell of a lot easier.

Zend Soap

Everyone hates SOAP.  But this made it usable.  Because of my application, I have to communicate with a 3rd party API server to store and retrieve information.  Don't hate.

Console

Although I haven't used it yet in my application, the Symfony Console will allow me to write quick commands and run them in shell/command prompt very easily.  I have written a Soap tester service that will allow me to plug in a WSDL url and pull up all the commands and make Soap calls.  It was my first experience with it, but it worked well.

If you are familiar with writing console commands in Laravel (Artisan commands), this will feel fairly natural.  Of course there is some configuration, either including the application, or just components, you will be able to get your job done quickly.

Config/Config service provider

This service provider allows you to specify config files and load up the configurations into your application.  I wrote dev.yml and prod.yml files and inject them into my application to load up settings differently.

Memcache

I don't use Redis, but I use Memcache fairly extensively.  I have move to storing PHP sessions in cache rather than the file system.  I saw huge performance increases by this move alone.  Memcache is not persistent, and will be deleted when the server is restarted, but it is blazingly fast.  A monitor on one of my servers shows that it takes an average of 0.00015 seconds to connect to the Memcache service and retrieve a key.  Since we are executing Soap requests to a remote server which take 0.01 seconds to get a result, utilizing Memcache to store those responses significantly speeds up the application.


My next article will be going over the initial configuration of the Silex application, and the tweaks I made and my reasons behind it.

No comments:

Post a Comment