cancel
Showing results for 
Search instead for 
Did you mean: 

Can't enable production mode ;)

Can't enable production mode ;)

Hi to all. I'm finalizing my store powered by magento 2.1.5 CE. I've checked perfomance on my local virtualmachine with lots of hardware resources assigned, but I still experienced a bit slow opening a product the first time. I know that magento caches improve this a lot, but still I find it to slow, about 10 sec to open a product, hmmmm. So I've googled around and found out that I should switch to production mode. I tried to run

magento deploy:mode:set production

but while this process does also compilation it failed. Ok, so I tried to run compilation as separate command to get more details:

magento setup:di:compile

and I got some weired exception I can't solve now, it says:

  [Exception]
  Notice: Uninitialized string offset: 1 in /var/www/mywebsite.com/html/setup/src/Magento/Setup/Module/Di/Code/Reader/F
  ileScanner.php on line 322

I googled around and someone says it's a bug of this version here

Now I wonder, how do I switch to production mode otherwise, is it possible at all. Besides, approx how much performance improvements can I expect in "production mode". Are there any other ways to improve product page loading?

 

Any input welcome, please suggest. Thank in advance.

 

8 REPLIES 8

Re: Can't enable production mode ;)

@tofi

 

Best is to remove the following directories from {magento_root}/var directory and then redeploy magento: 

  • generation
  • page_cache
  • view_preprocessed
  • di

Once you have removed the above, run system upgrade command in the CLI and redeploy everything. 


I hope it will fix the issue Smiley Happy 

Magento Certified Solution Specialist | Lead Magento developer
If this response was helpful to you, consider giving kudos to this post

Re: Can't enable production mode ;)

Hi Shoaib and thanks for info, but are you sure this is the right way? Is this just running?

php bin/magento setup:upgrade

I don't want  to get things worse than they are...

I also tried running

php bin/magento deploy:mode:set production --skip-compilation

that did set the production mode, but now the entire store doesn't work. In var/log I have full o these:

[2017-03-22 11:17:35] main.DEBUG: cache_invalidate:  {"method":"GET","url":"http:/","invalidateInfo":{"identifier":"DB_PDO_MYSQL_DDL_mg_catalogsearch_fulltext_scope1_3"},"is_exception":false} []
[2017-03-22 11:17:35] main.DEBUG: cache_invalidate:  {"method":"GET","url":"http:/","invalidateInfo":{"identifier":"DB_PDO_MYSQL_DDL_mg_catalogsearch_fulltext_scope1_4"},"is_exception":false} []
[2017-03-22 11:17:38] main.DEBUG: cache_invalidate:  {"method":"GET","url":"http:/","invalidateInfo":{"identifier":"request_declaration"},"is_exception":false} []
[2017-03-22 11:22:08] main.DEBUG: cache_invalidate:  {"method":"GET","url":"http:/","invalidateInfo":{"tags":["interception","CONFIG"],"mode":"matchingTag"},"is_exception":false} []
[2017-03-22 11:22:09] main.DEBUG: cache_invalidate:  {"method":"GET","url":"http:/","invalidateInfo":{"tags":[],"mode":"all"},"is_exception":false} []
[2017-03-22 11:22:09] main.DEBUG: cache_invalidate:  {"method":"GET","url":"http:/","invalidateInfo":{"tags":[],"mode":"all"},"is_exception":false} []
[2017-03-22 11:22:09] main.DEBUG: cache_invalidate:  {"method":"GET","url":"http:/","invalidateInfo":{"tags":["interception","CONFIG"],"mode":"matchingTag"},"is_exception":false} []
[2017-03-22 11:22:34] main.DEBUG: cache_invalidate:  {"method":"GET","url":"http:/","invalidateInfo":{"tags":["interception","CONFIG"],"mode":"matchingTag"},"is_exception":false} []
[2017-03-22 11:24:35] main.DEBUG: cache_invalidate:  {"method":"GET","url":"http://mywebpage.com/","invalidateInfo":{"tags":["interception","CONFIG"],"mode":"matchingTag"},"is_exception":false} []
[2017-03-22 11:29:35] main.DEBUG: cache_invalidate:  {"method":"GET","url":"http://mywebpage.com/","invalidateInfo":{"tags":["interception","CONFIG"],"mode":"matchingTag"},"is_exception":false} []

Can you please explain what these lines of "cache_invalidate" mean, can I solve this somehow. In the meantime I have run

php bin/magento deploy:mode:set developer

And my store is functional again, but am very interested in your solution, but really don't want to crash everything now. Much thanks again.

Re: Can't enable production mode ;)

@tofi

 

I agree - we don't want to break the store at all.


From my understanding the problem is with the code compilation and it can only be fixed by trying to rerun the compilation. 

 

Just so I know - did you try to run the following? 

php bin/magento setup:di:compile

Finally about the cache_invalidate, it clearly says that you cache is out of date. Just run the following to fix it: 

php bin/magento cache:flush
php bin/magento cache:clean

I hope it will fix it. 

 

Please let me know if the problem persists. 

 

Magento Certified Solution Specialist | Lead Magento developer
If this response was helpful to you, consider giving kudos to this post

Re: Can't enable production mode ;)

Thanks. You are right about "cache_invalidate" errors, I was trying to solved this by manually deleting content of var/cache and var/page_cache, but obviously that was not enough, I should have run the command as suggested.

 

Yes I have run the compile command separately and here is what I get:

Compilation was started.
Repositories code generation... 1/7 [====>-----------------------]  14% 1 sec 92.0 MiB

                                                                                                                               
  [Exception]                                                                                                                  
  Notice: Uninitialized string offset: 1 in /var/www/mywebpage.com/html/setup/src/Magento/Setup/Module/Di/Code/Reader/Fil  
  eScanner.php on line 322                                                                                                     
                                                                                                                               


setup:di:compile


magento@srv:/var/www/mywebpage.com/html$ 

Would running upgrade as you previously suggested help in this case? I guess it will run the compile in the upgrade process, am I right?

Re: Can't enable production mode ;)

Time to revive this thread Smiley Wink I've been playing with this for a while and found out that compilation failed because of poorly programmed additional modules I've installed, that were Magebuzz_Helpdesk and Magebuzz_Socialshare. First I tried just to disable this two like this:

php-7.0.15 bin/magento module:disable Magebuzz_Socialshare

but it was not enough, compile still complained about the same error. So I had to completely remove them like so:

php-7.0.15 bin/magento module:uninstall Magebuzz_Socialshare

now the compile completed ok and I could also switch to production mode without problem.

 

Now the situation is like this. I would like to have both production mode because of better performance/security and also these two modules, even if they are a bit crappy coded so to speak, but they work and they are free Smiley Wink

 

So the main question now is, can I switch to production mode first and install this two modules afterwards? Much thanks for your input.

Re: Can't enable production mode ;)

Nope, doesn't go. Have just tried. Installing a module while in production mode is trying to run compile command at the end and of course in my case it fails...

Re: Can't enable production mode ;)

@tofi

 

Well you've just answered this question yourself Smiley Happy 

Whenever you switch to production mode, the entire codebase is compiled and themes generated. Switching to production mode means that you are happy with all the modules and you are happy for Magento to compile and setup all dependencies. 

 

In my opinion, best is to speak to the extension developers and get them to look at it (if they can) or wait for the next release Smiley Happy 

Magento Certified Solution Specialist | Lead Magento developer
If this response was helpful to you, consider giving kudos to this post

Re: Can't enable production mode ;)

Hi, thanks for feedback. I'm still struggling with this one. I've actually solved the issue, well at least it looks so as much as I've tested it. I've found out the critical part was the usage of 3-rd library "Recaptcha" in module Helpdesk. The runtime php class loading was done wrong or better said incompatible with php 7. I've adjusted the file autoload.php, the corrected part now looks like this

 

<?php

/* An autoloader for ReCaptcha\Foo classes. This should be require()d
 * by the user before attempting to instantiate any of the ReCaptcha
 * classes.
 */

//>custom_file_entry
//spl_autoload_register(function ($class) {
spl_autoload_register(function($class) {
//<custom_file_entry

    if (substr($class, 0, 10) !== 'ReCaptcha\\') {
      /* If the class does not lie under the "ReCaptcha" namespace,
       * then we can exit immediately.
       */
      return;
    }

Even though, still not sure why, but that white space in spl_autoload_register was causing troubles. Besides this, I had to manually add an include in file vendor/magebuzz/helpdesk/Library/recaptcha/ReCaptcha/RequestMethod/CurlPost.php. The corrected part now looks like

namespace ReCaptcha\RequestMethod;

//>custom_file_entry
//require_once('../RequestMethod.php');
require_once('/var/www/mywebpage.com/html/vendor/magebuzz/helpdesk/Library/recaptcha/ReCaptcha/RequestMethod.php');
//<custom_file_entry

use ReCaptcha\RequestMethod;
use ReCaptcha\RequestParameters;

/**
 * Sends cURL request to the reCAPTCHA service.
 * Note: this requires the cURL extension to be enabled in PHP
 * @see http://php.net/manual/en/book.curl.php
 */
class CurlPost implements RequestMethod

Yes, I agree the developers of this module should help, but I've tried to contact them a few times without success, they play deaf ones. It's true this module was free, but I'm willing to pay for a good work, or adjustment. Well I had to do it my self in the end. Maybe this helps someone else.