Setup of Mongo ODM in PHP 7 – performance considered

In a previous topic I have described our journey in optimising a symfony app ( the-journey-of-a-symfony-api-from-150ms-to-20ms ). Some of you have asked about specific configs, so here we go:

Install mongo-odm and the adapter:

php composer.phar require alcaeus/mongo-php-adapter
php composer.phar require doctrine/mongodb-odm-bundle

Now let’s configure it:

doctrine_mongodb:
    connections:
        default:
            server: mongodb://%mongo_server%
            options:
                connect: true
                connectTimeoutMS: 300 # as stated in the original post: timeouts are very important
    default_database: %database_name%
    document_managers:
        default:
            # this is also important to reduce disk usage, you could also use other backends for caching this
            metadata_cache_driver: apc   
            retry_connect:              1
            retry_query:                1
            auto_mapping: true

To have the best control I recommend to allow slave readonly only from code. For this you can simply use:

$this->mongo->getManager()->getClassMetadata(MyDocumentType::class)->slaveOkay = true

Install doctrine mongo bundle on php7 enviroments

I have recently made a new symfony project on php7 and I had a lot of problems installing mongo doctrine.

What I have tried:

  • Directly mention packages in composer.json and run composer update
  • Putting all new packages “@stable” version

None of the above worked, but I have found a very specific way that it worked and the order of the steps is very important:

php composer.phar require alcaeus/mongo-php-adapter
php composer.phar require doctrine/mongodb-odm-bundle

PHP 7

I have recently upgraded one of work project to PHP 7. What a bliss… Just by upgrading we have managed to reduce response time for Symfony based API from 100ms to 75ms (25% boost). (Note: responsibility of the decreased timing might also be from some updated libraries and drivers)
I have also managed to upgrade the present blog to the new PHP version and a similar improvement was observed.

Other major improvements from my perspective:

  • Strong type return methods (this can help increase the code quality and will help resolve some bugs in some early stages). I was a bit disappointed that overloading is still not available.
  • Syntax errors are now catchable

Cache Bundle for Symfony

Have you ever felt that your classes are burdened with caching logic instead of proper logic? I know you did, and so did I. In an effort to improve readability and quality of the code, me and my colleagues at eMAG have developed internally a library that will remove all the extra logic for caching from method body.

And after some time we have decided to open source it, so that others can also use it and help develop it.

The library is available on github: https://github.com/eMAGTechLabs/cachebundle . Also there is available also a small use guide.

 

wakup tool v2

Today i’ve worked hard to make some changes to “wakeup tool” and so it came v2.

Changes that worth mentioning:

  • New layout based on bootstrap. It’s responsive now ūüôā
  • Grouped hosts by type (Linux, Windows, Webserver). Each with it’s own verification procedure
  • Changed WOL mechanism in order to remove dependencies on some installed¬†binaries.
  • Changed autodiscovery mechanism. Now it will check if host alive trough checking ports 3389,22,80. Again removed dependencies on external binaries.
  • Changed log in mechanism to sfDoctrineGuard in order to allow future features that require permissions. If you require integration with Active Directory have a look here.

You can have a look yourself at: https://github.com/alexbumbacea/wakeup

wakeup tool

Today was the first expose to public of ¬†the wakeup tool. It’s available on github here¬†https://github.com/alexbumbacea/wakeup/

The tool is designed for companies that want to reduce the amount of power consumer by the computers while employees are not using them, but also offer possibility during VPN connections to access the machines.

It requires wake-on-lan to be enabled from bios and, for the auto-discovery functionality, it requires that computer would have Windows Shares enabled( it uses netbios scans ). Also computer may be added manually to the list.

Currently documentation and interface are still in work, but the core functionality is working.

Discover PHP 5.4

Finally i had the time to have a look at PHP 5.4, as i heard it had built in web server ( a cool feature for a windows user).

To shortly describe my requirements: a on demand webserver for Windows systems that would understand php, would allow easy configuration, a rewrite mechanism and preferably would not require any install process. All the criteria above were successfully implemented in php 5.4 as explained here. Continue reading Discover PHP 5.4