How can i put condition of maintenance mode in index file or Bootstap file in magento 2?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty margin-bottom:0;







up vote
2
down vote

favorite













How can i put condition of maintenance mode in index file or Bootstap
file in magento 2 ?




I want to check if Maintenance mode i enable or disable conditional base.



How can i check that in Index.php file or Bootstrap.php file in Magento 2 ?










share|improve this question



























    up vote
    2
    down vote

    favorite













    How can i put condition of maintenance mode in index file or Bootstap
    file in magento 2 ?




    I want to check if Maintenance mode i enable or disable conditional base.



    How can i check that in Index.php file or Bootstrap.php file in Magento 2 ?










    share|improve this question























      up vote
      2
      down vote

      favorite









      up vote
      2
      down vote

      favorite












      How can i put condition of maintenance mode in index file or Bootstap
      file in magento 2 ?




      I want to check if Maintenance mode i enable or disable conditional base.



      How can i check that in Index.php file or Bootstrap.php file in Magento 2 ?










      share|improve this question














      How can i put condition of maintenance mode in index file or Bootstap
      file in magento 2 ?




      I want to check if Maintenance mode i enable or disable conditional base.



      How can i check that in Index.php file or Bootstrap.php file in Magento 2 ?







      magento2 maintenance maintenance-flag






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked 42 mins ago









      Aditya Shah

      1,492422




      1,492422




















          3 Answers
          3






          active

          oldest

          votes

















          up vote
          1
          down vote



          accepted










          Try to use this code :



          <?php

          error_reporting(1);
          ini_set('max_execution_time', 0);
          use MagentoFrameworkAppBootstrap;

          require __DIR__ . '/app/bootstrap.php';
          $bootstrap = Bootstrap::create(BP, $_SERVER);
          $objectManager = $bootstrap->getObjectManager();
          $instance = MagentoFrameworkAppObjectManager::getInstance();
          $state = $objectManager->get('MagentoFrameworkAppState');
          $state->setAreaCode('frontend');
          $maintenanceMode = $instance ->get('MagentoFrameworkAppMaintenanceMode');
          $flag = $maintenanceMode->isOn();


          It maybe helpful for you.






          share|improve this answer




















          • Thanks @Rohan for the answer +1 :) let me try .
            – Aditya Shah
            36 mins ago











          • Is it index.php file @rohan ?
            – Aditya Shah
            35 mins ago










          • Please check my answer with code. You can use it in index.php
            – Mage2Dev
            34 mins ago










          • Yes. You can use in root file.
            – Rohan Hapani
            34 mins ago






          • 1




            Happy to help :) Happy Coding !!
            – Rohan Hapani
            27 mins ago

















          up vote
          1
          down vote













          If var/.maintenance.flag file does not exist, Magento operates normally, and maintenance mode is off. If it exists, maintenance mode is on. So you can write code for the same.



          $objManager = MagentoFrameworkAppObjectManager::getInstance();
          $maintenanceMode = $objManager->get('MagentoFrameworkAppMaintenanceMode');
          $flag = $maintenanceMode->isOn();





          share|improve this answer




















          • thanks for the answer +1 !
            – Aditya Shah
            28 mins ago

















          up vote
          1
          down vote













          Put below code in your index.php file



          $obj = $bootstrap->getObjectManager();

          $state = $obj->get('MagentoFrameworkAppState');
          $state->setAreaCode('frontend');

          $maintenanceMode = $obj ->get('MagentoFrameworkAppMaintenanceMode');
          $flag = $maintenanceMode->set(1);





          share|improve this answer




















          • thanks for the answer +1 !
            – Aditya Shah
            27 mins ago










          Your Answer







          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "479"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          convertImagesToLinks: false,
          noModals: false,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













           

          draft saved


          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f242975%2fhow-can-i-put-condition-of-maintenance-mode-in-index-file-or-bootstap-file-in-ma%23new-answer', 'question_page');

          );

          Post as a guest






























          3 Answers
          3






          active

          oldest

          votes








          3 Answers
          3






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          up vote
          1
          down vote



          accepted










          Try to use this code :



          <?php

          error_reporting(1);
          ini_set('max_execution_time', 0);
          use MagentoFrameworkAppBootstrap;

          require __DIR__ . '/app/bootstrap.php';
          $bootstrap = Bootstrap::create(BP, $_SERVER);
          $objectManager = $bootstrap->getObjectManager();
          $instance = MagentoFrameworkAppObjectManager::getInstance();
          $state = $objectManager->get('MagentoFrameworkAppState');
          $state->setAreaCode('frontend');
          $maintenanceMode = $instance ->get('MagentoFrameworkAppMaintenanceMode');
          $flag = $maintenanceMode->isOn();


          It maybe helpful for you.






          share|improve this answer




















          • Thanks @Rohan for the answer +1 :) let me try .
            – Aditya Shah
            36 mins ago











          • Is it index.php file @rohan ?
            – Aditya Shah
            35 mins ago










          • Please check my answer with code. You can use it in index.php
            – Mage2Dev
            34 mins ago










          • Yes. You can use in root file.
            – Rohan Hapani
            34 mins ago






          • 1




            Happy to help :) Happy Coding !!
            – Rohan Hapani
            27 mins ago














          up vote
          1
          down vote



          accepted










          Try to use this code :



          <?php

          error_reporting(1);
          ini_set('max_execution_time', 0);
          use MagentoFrameworkAppBootstrap;

          require __DIR__ . '/app/bootstrap.php';
          $bootstrap = Bootstrap::create(BP, $_SERVER);
          $objectManager = $bootstrap->getObjectManager();
          $instance = MagentoFrameworkAppObjectManager::getInstance();
          $state = $objectManager->get('MagentoFrameworkAppState');
          $state->setAreaCode('frontend');
          $maintenanceMode = $instance ->get('MagentoFrameworkAppMaintenanceMode');
          $flag = $maintenanceMode->isOn();


          It maybe helpful for you.






          share|improve this answer




















          • Thanks @Rohan for the answer +1 :) let me try .
            – Aditya Shah
            36 mins ago











          • Is it index.php file @rohan ?
            – Aditya Shah
            35 mins ago










          • Please check my answer with code. You can use it in index.php
            – Mage2Dev
            34 mins ago










          • Yes. You can use in root file.
            – Rohan Hapani
            34 mins ago






          • 1




            Happy to help :) Happy Coding !!
            – Rohan Hapani
            27 mins ago












          up vote
          1
          down vote



          accepted







          up vote
          1
          down vote



          accepted






          Try to use this code :



          <?php

          error_reporting(1);
          ini_set('max_execution_time', 0);
          use MagentoFrameworkAppBootstrap;

          require __DIR__ . '/app/bootstrap.php';
          $bootstrap = Bootstrap::create(BP, $_SERVER);
          $objectManager = $bootstrap->getObjectManager();
          $instance = MagentoFrameworkAppObjectManager::getInstance();
          $state = $objectManager->get('MagentoFrameworkAppState');
          $state->setAreaCode('frontend');
          $maintenanceMode = $instance ->get('MagentoFrameworkAppMaintenanceMode');
          $flag = $maintenanceMode->isOn();


          It maybe helpful for you.






          share|improve this answer












          Try to use this code :



          <?php

          error_reporting(1);
          ini_set('max_execution_time', 0);
          use MagentoFrameworkAppBootstrap;

          require __DIR__ . '/app/bootstrap.php';
          $bootstrap = Bootstrap::create(BP, $_SERVER);
          $objectManager = $bootstrap->getObjectManager();
          $instance = MagentoFrameworkAppObjectManager::getInstance();
          $state = $objectManager->get('MagentoFrameworkAppState');
          $state->setAreaCode('frontend');
          $maintenanceMode = $instance ->get('MagentoFrameworkAppMaintenanceMode');
          $flag = $maintenanceMode->isOn();


          It maybe helpful for you.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered 38 mins ago









          Rohan Hapani

          3,46211456




          3,46211456











          • Thanks @Rohan for the answer +1 :) let me try .
            – Aditya Shah
            36 mins ago











          • Is it index.php file @rohan ?
            – Aditya Shah
            35 mins ago










          • Please check my answer with code. You can use it in index.php
            – Mage2Dev
            34 mins ago










          • Yes. You can use in root file.
            – Rohan Hapani
            34 mins ago






          • 1




            Happy to help :) Happy Coding !!
            – Rohan Hapani
            27 mins ago
















          • Thanks @Rohan for the answer +1 :) let me try .
            – Aditya Shah
            36 mins ago











          • Is it index.php file @rohan ?
            – Aditya Shah
            35 mins ago










          • Please check my answer with code. You can use it in index.php
            – Mage2Dev
            34 mins ago










          • Yes. You can use in root file.
            – Rohan Hapani
            34 mins ago






          • 1




            Happy to help :) Happy Coding !!
            – Rohan Hapani
            27 mins ago















          Thanks @Rohan for the answer +1 :) let me try .
          – Aditya Shah
          36 mins ago





          Thanks @Rohan for the answer +1 :) let me try .
          – Aditya Shah
          36 mins ago













          Is it index.php file @rohan ?
          – Aditya Shah
          35 mins ago




          Is it index.php file @rohan ?
          – Aditya Shah
          35 mins ago












          Please check my answer with code. You can use it in index.php
          – Mage2Dev
          34 mins ago




          Please check my answer with code. You can use it in index.php
          – Mage2Dev
          34 mins ago












          Yes. You can use in root file.
          – Rohan Hapani
          34 mins ago




          Yes. You can use in root file.
          – Rohan Hapani
          34 mins ago




          1




          1




          Happy to help :) Happy Coding !!
          – Rohan Hapani
          27 mins ago




          Happy to help :) Happy Coding !!
          – Rohan Hapani
          27 mins ago












          up vote
          1
          down vote













          If var/.maintenance.flag file does not exist, Magento operates normally, and maintenance mode is off. If it exists, maintenance mode is on. So you can write code for the same.



          $objManager = MagentoFrameworkAppObjectManager::getInstance();
          $maintenanceMode = $objManager->get('MagentoFrameworkAppMaintenanceMode');
          $flag = $maintenanceMode->isOn();





          share|improve this answer




















          • thanks for the answer +1 !
            – Aditya Shah
            28 mins ago














          up vote
          1
          down vote













          If var/.maintenance.flag file does not exist, Magento operates normally, and maintenance mode is off. If it exists, maintenance mode is on. So you can write code for the same.



          $objManager = MagentoFrameworkAppObjectManager::getInstance();
          $maintenanceMode = $objManager->get('MagentoFrameworkAppMaintenanceMode');
          $flag = $maintenanceMode->isOn();





          share|improve this answer




















          • thanks for the answer +1 !
            – Aditya Shah
            28 mins ago












          up vote
          1
          down vote










          up vote
          1
          down vote









          If var/.maintenance.flag file does not exist, Magento operates normally, and maintenance mode is off. If it exists, maintenance mode is on. So you can write code for the same.



          $objManager = MagentoFrameworkAppObjectManager::getInstance();
          $maintenanceMode = $objManager->get('MagentoFrameworkAppMaintenanceMode');
          $flag = $maintenanceMode->isOn();





          share|improve this answer












          If var/.maintenance.flag file does not exist, Magento operates normally, and maintenance mode is off. If it exists, maintenance mode is on. So you can write code for the same.



          $objManager = MagentoFrameworkAppObjectManager::getInstance();
          $maintenanceMode = $objManager->get('MagentoFrameworkAppMaintenanceMode');
          $flag = $maintenanceMode->isOn();






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered 39 mins ago









          Mage2Dev

          3,1421919




          3,1421919











          • thanks for the answer +1 !
            – Aditya Shah
            28 mins ago
















          • thanks for the answer +1 !
            – Aditya Shah
            28 mins ago















          thanks for the answer +1 !
          – Aditya Shah
          28 mins ago




          thanks for the answer +1 !
          – Aditya Shah
          28 mins ago










          up vote
          1
          down vote













          Put below code in your index.php file



          $obj = $bootstrap->getObjectManager();

          $state = $obj->get('MagentoFrameworkAppState');
          $state->setAreaCode('frontend');

          $maintenanceMode = $obj ->get('MagentoFrameworkAppMaintenanceMode');
          $flag = $maintenanceMode->set(1);





          share|improve this answer




















          • thanks for the answer +1 !
            – Aditya Shah
            27 mins ago














          up vote
          1
          down vote













          Put below code in your index.php file



          $obj = $bootstrap->getObjectManager();

          $state = $obj->get('MagentoFrameworkAppState');
          $state->setAreaCode('frontend');

          $maintenanceMode = $obj ->get('MagentoFrameworkAppMaintenanceMode');
          $flag = $maintenanceMode->set(1);





          share|improve this answer




















          • thanks for the answer +1 !
            – Aditya Shah
            27 mins ago












          up vote
          1
          down vote










          up vote
          1
          down vote









          Put below code in your index.php file



          $obj = $bootstrap->getObjectManager();

          $state = $obj->get('MagentoFrameworkAppState');
          $state->setAreaCode('frontend');

          $maintenanceMode = $obj ->get('MagentoFrameworkAppMaintenanceMode');
          $flag = $maintenanceMode->set(1);





          share|improve this answer












          Put below code in your index.php file



          $obj = $bootstrap->getObjectManager();

          $state = $obj->get('MagentoFrameworkAppState');
          $state->setAreaCode('frontend');

          $maintenanceMode = $obj ->get('MagentoFrameworkAppMaintenanceMode');
          $flag = $maintenanceMode->set(1);






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered 29 mins ago









          Ansar Husain

          1,351217




          1,351217











          • thanks for the answer +1 !
            – Aditya Shah
            27 mins ago
















          • thanks for the answer +1 !
            – Aditya Shah
            27 mins ago















          thanks for the answer +1 !
          – Aditya Shah
          27 mins ago




          thanks for the answer +1 !
          – Aditya Shah
          27 mins ago

















           

          draft saved


          draft discarded















































           


          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f242975%2fhow-can-i-put-condition-of-maintenance-mode-in-index-file-or-bootstap-file-in-ma%23new-answer', 'question_page');

          );

          Post as a guest













































































          Comments

          Popular posts from this blog

          What does second last employer means? [closed]

          Installing NextGIS Connect into QGIS 3?

          One-line joke