• Overview
    Frameworks
    • Drupal
    • WordPress
    • Symfony
    • Magento
    • See all frameworks
    Features
    • Observability
    • Auto-scaling
    Solutions
    • Marketing Teams
    • Retail
    • Higher Education
  • Pricing
  • Featured articles
    • Switching to Platform.sh can help IT/DevOps organizations drive 219% ROI
    • Organizations, the ultimate way to manage your users and projects
  • Support
  • Docs
  • Contact
  • Login
  • Free Trial
Blog
Thumbnail

What will you do after you deploy?

php
April 17, 2018
Larry Garfield
Larry Garfield
Director of Developer Experience

A key part of Platform.sh's benefit comes from its integrated build and deploy hooks. Deploying a new version of your site or application rarely means simply dumping what's in Git onto a server anymore. Platform.sh was built from the ground up to let you execute whatever commands you need to "build" your application — turning what's in Git into what's actually on the server — and then to "deploy" the application — cleanup tasks like database migrations that should be run before the site is opened to visitors again.

There's a caveat there, however. Some deploy tasks need to block the site from new visitors until they complete; think updating the database schema, for instance. Others may not really need exclusive access to the site, but they still get it. That keeps the site unresponsive for critical seconds until those tasks complete.

So, let's fix that. We've now added a third hook, post_deploy. It works pretty much as you'd expect. You can do all the same things in it that you can do with a deploy hook, but it runs after the site is reopened to the world to accept new requests. Any tasks that don't need exclusive access to the database can be moved there, keeping the site up and responsive as much as possible while allowing for more robust and flexible automated tasks.

For example, the following configuration would run any pending database updates as part of the deploy hook but then import new content in the post_deploy hook. The new content will become available as soon as possible but the site will still be up and running while it's being updated. Once the import is done we'll also clear the cache a second time to ensure the new content is visible to the next request.

hooks:
    deploy: |
        set -e
        update_db.php
        clear_cache.php
    post_deploy: |
        set -e
        migrate_content.php import/
        clear_cache.php

What's "safe" to move to the post_deploy hook? That's up to you. What does or does not need an exclusive database lock will vary by site. Sometimes a cache clear is safe to do post-open, other times not. You get to make that determination for your application.

See the hook documentation for more information, and enjoy faster deploy tasks.

Get the latest Platform.sh news and resources
Subscribe

Related Content

Cover image

PHP 8.1 lays new ground on Platform.sh

Company

AboutSecurity and complianceTrust CenterBoard and investorsCareersPressContact us
System StatusPrivacyTerms of ServiceImpressumWCAG ComplianceManage your cookie preferencesReport a security issue
© 2022 Platform.sh. All rights reserved.
Supported by Horizon 2020's SME Instrument - European Commission 🇪🇺