Skip to main content

Posts

Setting up a Symfony2 REST service with FOSRestBundle

Installation First thing is to download and setup the FOSRestBundle. If you are running Symfony 2.0.x, get the FOSRestBundle version 0.6, otherwise, download the code in the master branch. The FOSRestBundle depends on the JMSSerializerBundle so the following instructions are going to include some extra information for setting up this bundle to complete our REST service. First thing is to install our dependencies. Add the following to your deps file: [metadata] git=http://github.com/schmittjoh/metadata.git version=1.1.0 [JMSSerializerBundle] git=git://github.com/schmittjoh/JMSSerializerBundle.git target=bundles/JMS/SerializerBundle [FOSRest] git=git://github.com/FriendsOfSymfony/FOSRest.git target=fos/FOS/Rest [FOSRestBundle] git=git://github.com/FriendsOfSymfony/FOSRestBundle.git target=bundles/FOS/RestBundle version=origin/0.6 Run the vendors script to install these bundles: php bin/vendors install Next, update your app/autoload.php file...

Securing Symfony2 REST services with FOSOAuthServerBundle

Overview In my previous article, I wrote about setting up a Symfony2 REST service using FOSRestBundle. However, this REST service was behind a firewall protected by a generic form_login provider. Not really ideal if you wish to open your REST API to other applications. So in this article, I will try to explain how to set up FOSOAuthServerBundle to protect your REST API methods using OAuth2. Before we start getting into the gritty details, it is a good idea to have a look at the official OAuth2 documentation . Let's begin... FOSOAuthServerBundle Installation You have to install v1.1.0 of FOSOAuthServerBundle if you are using Symfony 2.0.x. If not, see the docs . First, add the following entries to your deps file: [FOSOAuthServerBundle] git=git://github.com/FriendsOfSymfony/FOSOAuthServerBundle.git target=bundles/FOS/OAuthServerBundle version=origin/1.1.x [oauth2-php] git=git://github.com/FriendsOfSymfony/oauth2-php.git Run the vendors script to install these...

Some interesting news and articles

Here is a couple of news/articles/announcements that I have found interesting recently: The Case for the /usr Merge is definitely an interesting read. You can also have this functionality by upgrading to Fedora 17. Overview of new features in Apache HTTP Server 2.4 is obviously a must read. Besides the performance gains, I also find the KeepAliveTimeout upgrade - the ability to set this configuration option in microseconds - significant. This functionality can shave off those milliseconds spent for setting up a connection on AJAX heavy pages while not degrading overall server performance. PHP 5.4 is out if you haven't heard. Traits and a built-in web server for development purposes. Nice! I hate dealing with HTML so anything that helps me with this headache deserves some respect. Check out the Page Inspector 3D View (nicknamed Tilt).

Upgrading to Fedora 16

Finally had some time to upgrade my Fedora 14 distribution to Fedora 16. I followed the YUM upgrade instructions on the Fedora website. Having never had good luck with odd Fedora releases, I will be skipping Fedora 17 for now and waiting for 18 instead. Overall, The Fedora 15 upgrade was smooth and the reboot of my dual-boot system was successful. However, the following Fedora 16 upgrade presented me with a blank GRUB screen after reboot even though I followed the instructions line by line. At the end, I had to create a Fedora 16 DVD, boot into rescue mode, re-run the GRUB setup commands again: chroot /mnt/sysimage /sbin/grub2-mkconfig -o /boot/grub2/grub.cfg /sbin/grub2-install BOOTDEVICE After dealing with the usual sound problems, the system was up and running with the dual-boot GRUB setup still intact. At this point, a couple of changes have come to my attention. There is a new systemd component that handles system services. Runlevels concept is replaced by targets instead...

Passing PHP data to Apache access logs

Recently, I worked on a project to collect performance data from an application at work and pass that data to Apache access logs as part of a performance improvement project. As it turns out, PHP has a built-in function called apache_note() that your can use for this purpose. For example, if you wish to pass memory usage information to Apache access logs, add the following code to at the end of your front controller file: if (php_sapi_name() != 'cli') { apache_note('PHPMemoryUsage', memory_get_peak_usage(true)); } Then, update your Apache LogFormat directive to include this new piece of information: LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %{PHPMemoryUsage}n" combined

Mapping embedded documents in Doctrine MongoDB ODM

If you have a MongoDB document that has another document embedded in it, you still have to create a separate XML mapping document for the embedded one. So if you have a parent document called Activity that has an embedded document called Coordinates , the configuration would look something like this: src/Acme/ActivityBundle/Resources/config/doctrine/Activity.mongodb.xml <doctrine-mongo-mapping xmlns="http://doctrine-project.org/schemas/odm/doctrine-mongo-mapping" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://doctrine-project.org/schemas/odm/doctrine-mongo-mapping http://doctrine-project.org/schemas/odm/doctrine-mongo-mapping.xsd"> <document name="Acme\ActivityBundle\Document\Activity" db="acme" collection="activity" customId="true"> <field fieldName="id" id="true" strategy="INCREMENT...