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 : http://php.net/manual/en/function.usort.php
http://stackoverflow.com/questions/4282413/php-sort-array-of-objects-by-object-fields

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:

http://domain.com/image/mi-text-with-dots-.-in-.-the-.-middle.png

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:

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

Ref: http://stackoverflow.com/questions/18098583/error-in-symfony2-when-url-cointains-dot

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

logo-composer-transparent

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

Ref: http://widgetbook.blogspot.com.es/2013/08/mongodb-and-macports-and-v8.html

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