Sylius: Out of memory on 256MB Shared hosting

Created on 22 Mar 2016  Â·  9Comments  Â·  Source: Sylius/Sylius

Hello everyone,

I'm developing my ecommerce website using Sylius. Everything is fine on my computer. But Sylius v0.17 project doesnt work on shared hosting which has 256MB. Version 0.16 works. I want to install on shared hosting because this is cheapest plan. Does Sylius 0.17 require dedicated or vps hosting?

Help Wanted

Most helpful comment

@tbatbayar,

0.17 makes the container much larger and compiling this is probably pushing you over the memory limit.

There is a fix coming soon to Symfony which will reduce memory consumption when generating the container, for now you can add the following to your AppKernel.php file:

    /**
     * The following 2 methods workaround the enormous memory usage of token_get_all() which is used in
     * stripComments() below.
     *
     * Instead of calling token_get_all() we use php_strip_whitespace() which is actually more aggressive stripping
     * and results in a smaller cached container.
     *
     * However this can only be run against a file (not a string).
     * So we dump the container as normal without any stripping, then afterwards strip and re-save the container
     *
     * This resulted in a decrease in total memory consumption of the process that builds the container
     * from 350mb to <50mb in PHP7, which will allow it to be built on Platform.sh
     *
     * PW, 03/2016
     *
     * {@inheritdoc}
     */
    public function dumpContainer(ConfigCache $cache, ContainerBuilder $container, $class, $baseClass)
    {
        parent::dumpContainer($cache, $container, $class, $baseClass);

        if (!$this->debug) {
            $cache->write(php_strip_whitespace($cache->getPath()), $container->getResources());
        }
    }

    /**
     * {@inheritdoc}
     */
    public static function stripComments($source)
    {
        return $source;
    }

Then make sure you run cache:clear before you access a web page.

If this still runs out of memory, try the following instead:

php app/console cache:warmup --no-optional-warmers

All 9 comments

@tbatbayar,

0.17 makes the container much larger and compiling this is probably pushing you over the memory limit.

There is a fix coming soon to Symfony which will reduce memory consumption when generating the container, for now you can add the following to your AppKernel.php file:

    /**
     * The following 2 methods workaround the enormous memory usage of token_get_all() which is used in
     * stripComments() below.
     *
     * Instead of calling token_get_all() we use php_strip_whitespace() which is actually more aggressive stripping
     * and results in a smaller cached container.
     *
     * However this can only be run against a file (not a string).
     * So we dump the container as normal without any stripping, then afterwards strip and re-save the container
     *
     * This resulted in a decrease in total memory consumption of the process that builds the container
     * from 350mb to <50mb in PHP7, which will allow it to be built on Platform.sh
     *
     * PW, 03/2016
     *
     * {@inheritdoc}
     */
    public function dumpContainer(ConfigCache $cache, ContainerBuilder $container, $class, $baseClass)
    {
        parent::dumpContainer($cache, $container, $class, $baseClass);

        if (!$this->debug) {
            $cache->write(php_strip_whitespace($cache->getPath()), $container->getResources());
        }
    }

    /**
     * {@inheritdoc}
     */
    public static function stripComments($source)
    {
        return $source;
    }

Then make sure you run cache:clear before you access a web page.

If this still runs out of memory, try the following instead:

php app/console cache:warmup --no-optional-warmers

Thank you Peter Ward,

It works fine. I'm really appreciate.

no problem, glad I could help!

This is not working in my current version of Sylius 1.0 beta. Is there any other solution for this version?

@kubrtj request additional memory. 256mb for production is kinda funny.
Note that on php7 sylius uses only about 10-12mb in production mode, meaning that only container rebuilding requires such a vast amount of RAM. This is more symfony-related problem rather than sylius.

I try install Sylius in producton enviroment on shared webhosting with PHP option memory_limit 128MB, but it ending with Fatal error: Allowed memory size of 134217728 bytes exhausted

Any idea how to solve it?

`php bin/console sylius:install --env=prod --no-debug
Installing Sylius...

Step 1 of 4. Checking system requirements.
+-----------------------------------------------+----------------+
| Issue | Recommendation |
+-----------------------------------------------+----------------+
| sylius.installer.settings.version_recommended | |
+-----------------------------------------------+----------------+
Success! Your system can run Sylius properly.

Step 2 of 4. Setting up the database.
Creating Sylius database for environment prod.
It appears that your database already exists. Would you like to reset it? (y/N) y
0/5 [| ] 0%
1/5 [|||||| ] 20%
2/5 [|||||||||||| ] 40%
3/5 [||||||||||||||||| ] 60%PHP Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 245760 bytes) in /www/sylius/vendor/symfony/symfony/src/Symfony/Component/Translation/Translator.php on line 329

Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 245760 bytes) in /www/sylius/vendor/symfony/symfony/src/Symfony/Component/Translation/Translator.php on line 329

[Symfony\Component\Debug\Exception\OutOfMemoryException]
Error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 245760 bytes)

cache:clear [--no-warmup] [--no-optional-warmers] [-h|--help] [-q|--quiet] [-v|vv|vvv|--verbose] [-V|--version] [--ansi] [--no-ansi] [-n|--no-interaction] [-e|--env ENV] [--no-debug] [--] `

@kubrtj you need minimum 512MB for Sylius to install and run properly.

I have gotten Symfony to run on a shared server once by compiling the container / setting up database locally then pushing the prod cache up to it by SFTP. You can dump your local database and just load the SQL as well. It's not a great solution but worth a try.

Sylius should be run on VPS or Dedicated Server. You can try Platform.sh (check our demo for config). Shared Hosting will not provide optimal user experience.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

inssein picture inssein  Â·  3Comments

eb22fbb4 picture eb22fbb4  Â·  3Comments

mikemix picture mikemix  Â·  3Comments

crbelaus picture crbelaus  Â·  3Comments

loic425 picture loic425  Â·  3Comments