How to disable a website for a specific time within zend?

I am using zend framework. Sometimes I want to disable or lower my site for a certain time for maintenance. So, how can I stop people from accessing any page of my site when necessary?

Where is the bottleneck in the Zend Framework where I can stop all requests and stop the user.

thanks

+6
source share
3 answers

The tricky part of this action in a ZF application is that, apparently, your service will affect the application itself. Thus, if the application is โ€œbrokenโ€ during maintenance, the risk is that the in-app solution may also break. In this sense, โ€œexternalโ€ approaches, such as modifying .htaccess or setting up the public/index.php file, are probably more reliable.

However, the in-app approach may use the front controller plugin. In application/plugins/TimedMaintenance.php :

 class Application_Plugin_TimedMaintenance extends Zend_Controller_Plugin_Abstract { protected $start; protected $end; public function __construct($start, $end) { // Validation to ensure date formats are correct is // left as an exercise for the reader. Ha! Always wanted // to do that. ;-) if ($start > $end){ throw new Exception('Start must precede end'); } $this->start = $start; $this->end = $end; } public function routeShutdown(Zend_Controller_Request_Abstract $request) { $now = date('Ymd H:i:s'); if ($this->start <= $now && $now <= $this->end){ $request->setModuleName('default') ->setControllerName('maintenance') ->setActionName('index'); } } } 

Then register the plugin in application/Bootstrap.php :

 protected function _initPlugin() { $this->bootstrap('frontController'); $front = $this->getResource('frontController'); $start = '2012-01-15 05:00:00'; $end = '2012-01-15 06:00:00'; $plugin = new Application_Plugin_TimedMaintenance($start, $end); $front->registerPlugin($plugin); } 

In practice, you may need a start and end time before configuration. In application/configs/application.ini :

 maintenance.enable = true maintenance.start = "2012-01-15 05:00:00" maintenance.end = "2012-01-15 06:00:00" 

Then you can change the registration of the plugin to look like this:

 protected function _initPlugin() { $this->bootstrap('frontController'); $front = $this->getResource('frontController'); $config = $this->config['maintenance']; if ($config['enable']){ $start = $config['start']; $end = $config['end']; $plugin = new Application_Plugin_TimedMaintenance($start, $end); $front->registerPlugin($plugin); } } 

This way, you can enable maintenance mode by simply editing the configuration record.

+7
source

It's simple.

Use htaccess rewrite and redirect the entire request to a static temporary page instead of sending to bootstrap or index file

+7
source

The rewrite rule in the .htaccess file directs all traffic through index.php, so if you cannot change .htaccess, simply place the next line in index.php in front of any of the ZF-related materials.

 $maintenanceStart = new DateTime('2012-01-01 00:00:00'); $maintenanceEnd = new DateTime('2012-01-01 01:00:00'); $now = new DateTime; if ($now > $maintenanceStart && $now < $maintenanceEnd) { fpassthru('/path/to/your/maintenancePage.html'); exit; } 

Thus, none of the code associated with ZF will be executed during the maintenance window.

+7
source

Source: https://habr.com/ru/post/904798/


All Articles