Category Archives: Web

Order an array of objects in PHP by field

function cmp($a, $b)
    return strcmp($a->name, $b->name);

usort($your_data, "cmp");

Or the shorter version using closures:

usort($your_data, function($a, $b)
    return strcmp($a->name, $b->name);

Ref :

Symfony2 routing: Allow dots in URL

I have one route in my app that must have a text and a dot followed by a format. For example:

As you can see it’s an url that can contain dots before the dot that splits the {text} and the {_format} parts.

To make this work you have to define the route in routing.yml using a regexp for {text} this way:

    pattern:  /image/{text}.{_format}
    defaults: { _controller: AcmeDemoBundle:Demo:image, _format: png }
        _format: png|jpg
        text: .+


Fix “Fatal error: Allowed memory size of X bytes exhausted (tried to allocate X bytes)” with composer update

I got this error today when running composer update for one of my Symfony2 projects:

Fatal error: Allowed memory size of 536870912 bytes exhausted (tried to allocate 3781182 bytes) in phar:///usr/local/bin/composer/src/Composer/Util/RemoteFilesystem.php on line 202


Composers troubleshooting tells that you can increase the memory PHP can allocate editing memory_limit parameter in php.ini. I changed it from 128M to 512M but still didn’t work.

Finally the solution was to run composer update with no memory limit this way:

php -d memory_limit=-1 /usr/local/bin/composer update

“WARNING: soft rlimits too low” in MongoDB with Mac OS X

If you get this warning when you connect to mongo shell in Mac OX X:

** WARNING: soft rlimits too low. Number of files is 256, should be at least 1000

You can increase that limit by just running this on the Mac OS X shell:

launchctl limit maxfiles 1024 1024

This other command has the same effect but it will only last until the next system reboot:

ulimit -n 1024

Restart mongod and it shouldn’t complain any more.

Solve “mongodb cannot be built while v8 is active” in MacPorts

While updating all the ports of macports I got this error:

--->  Configuring mongodb
Error: mongodb cannot be built while v8 is active.
Error: Please deactivate v8 and try again.
Error: You can reactivate v8 again later.
Error: org.macports.configure for port mongodb returned: v8 is active

To deactivate v8 run:

sudo port -f deactivate v8

Run the update process again:

sudo port upgrade outdated

And finally activate v8 again:

sudo port activate v8


  • Page 1 of 7
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • >