Is your task running out of memory?
Sometimes when you execute a task in Symfony, it may run out of memory. Resizing images is a prime example. You could of course tweak php.ini to allow scripts to consume more memory, but you can also overwrite the ini values on the command line like so:
php -d memory_limit=1024M symfony [your-task]
Or, overwrite several values:
php -d memory_limit=1024M -d max_execution_time=0 symfony [your-task]
One Comment
→
Yes, this is a handy way of starting PHP with a higher memory limit when needed.
Other things that help:
* Using array hydration rather than object hydration in Doctrine pays off pretty hugely (but only if you don’t need write access).
* Breaking tasks up. Rather than reindexing 6,000 web pages, have a table of “dirty” pages that need reindexing and a task that reindexes the first 100 pages mentioned in the table on any given run, thus never running out of memory. If you need to reindex them all, just mark them all and then fire off that task via system() (a separate invocation via PHP) in a loop until you no longer have dirty pages to reindex.
* When all else fails, consider using PDO – it’s not that bad really and memory requirements are vastly lower.
These are our preferred solutions in the Apostrophe CMS.