Skip to main content

Posts

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...

Creating a Symfony2 helper

While working on a Symfony2 project yesterday, I realized I needed a better way to format dates in my templates. The reason behind this was the fact that my MongoDB document entities contained date values that were either null or DateTime instances. This entailed using a bunch of if statements for extra checks that made template code unnecessarily verbose. My solution was to create a template helper in an application specific framework bundle that I had created previously to contain all common assets and other necessary common resources. Create a Helper directory in the framework bundle directory and create a DateHelper class: src/Acme/FrameworkBundle/Helper/DateHelper.php namespace Acme\FrameworkBundle\Helper; use Symfony\Component\Templating\Helper\Helper; class DateHelper extends Helper { protected $options; public function __construct(array $options) { $this->options = $options; } public function getName() { return ...

Adding post-login logic to FOSUserBundle

Having finally figured out how to use FOSUserBundle in my project, I decided to keep track of all logins next. The implementation turned out to be a breeze thanks to Symfony2's security listener mechanism. As usual, the first step is to create a MongoDB document for this purpose. This is a very simple document that contains a user's id, session id, IP address, and login date. src/Acme/UserBundle/Document/LoginHistory.php namespace Acme\UserBundle\Document; class LoginHistory { protected $id; protected $userId; protected $sessionId; protected $ip; protected $createdAt; /** * Get id * * @return custom_id $id */ public function getId() { return $this->id; } /** * Set userId * * @param int $userId */ public function setUserId($userId) { $this->userId = $userId; } /** * Get userId * * @return int $userId */ public function getUserId...