22media's avatar

Deploying as an Azure Web App

I'm encountering a problem trying to deploy a fresh L5.2 app on Azure as a Web App. I configured deployment via a git push but it seems that the deployment hangs at php artisan clear-compiled until a timeout occurs.

[master]$ git push azure master
Password for 'https://[redacted]@[redacted].scm.azurewebsites.net:443': 
Counting objects: 1, done.
Writing objects: 100% (1/1), 200 bytes | 0 bytes/s, done.
Total 1 (delta 0), reused 0 (delta 0)
remote: Updating branch 'master'.
remote: Updating submodules.
remote: Preparing deployment for commit id 'db7b092bbd'.
remote: Running custom deployment command...
remote: Running deployment command...
remote: Install Dependencies with Composer
remote: .
remote: Loading composer repositories with package information
remote: Installing dependencies from lock file
remote: Nothing to install or update
remote: Generating optimized autoload files
remote: ..........................................................
remote: > php artisan clear-compiled
remote: ....................................................................................................................................................................................................
remote: 
remote: 
remote:                                                                                  
remote:   [Symfony\Component\Process\Exception\ProcessTimedOutException]                 
remote:   The process "php artisan clear-compiled" exceeded the timeout of 300 seconds.  
remote: An error has occurred during web site deployment.
remote:                                                                                  
remote: 
remote: 
remote: install [--prefer-source] [--prefer-dist] [--dry-run] [--dev] [--no-dev] [--no-plugins] [--no-custom-installers] [--no-autoloader] [--no-scripts] [--no-progress] [-v|vv|vvv|--verbose] [-o|--optimize-autoloader] [-a|--classmap-authoritative] [--ignore-platform-reqs] [--] [<packages>]...
remote: 
remote: 
remote: 
remote: Error - Changes committed to remote repository but deployment to website failed.
To https://[redacted]@[redacted].scm.azurewebsites.net:443/[redacted].git
   72a7f47..db7b092  master -> master

While all these is going on, the CPU on the Azure Web App host spikes to 100% and the Kudu admin is inaccessible. I believe that php artisan is running into a kind of CPU-intensive loop that prevents even the other w3wp.exe processes from running, but I am not sure.

This may be a shot in the dark as I believe not many of us deploy to Azure on Windows. But if anyone has any experience with this, help is appreciated!

0 likes
4 replies
nlehman06's avatar

I'm having the exact same issue. Did you ever get past this?

nlehman06's avatar

Got it to work by scaling up the App service plan from S1 to S3.

2 likes
22media's avatar
22media
OP
Best Answer
Level 4

I managed to get it to work on S1 by breaking up the steps performed in php artisan optimize into different scripts.

Digging into OptimizeCommand.php reveals that the optimize step performs two things in a production environment:

  1. Dumping an optimized composer autoloader (ie. composer dump-autoload -o)
  2. Compiling common framework classes and other classes as defined in config/compile.php.

Because composer dump-autoload -o is already performed in the dependency installation step (note the Generating optimized autoload files output above) we do not need to redo this in OptimizeCommand.php. I created my own Command subclass to handle the common class compilation and ran it in Composer's post-install-cmd.

I have an example Laravel 5.2 project with the fixes applied in https://github.com/leejunkit/vashti. You can take a look at my composer.json and CompileCommonClasses.php.

1 like
Marchie's avatar

Thanks for this! I've been tearing my hair out waiting for applications to deploy!

I've even tried modifying the Azure Composer Extension so that the --optimize autoloader option isn't used, but I think the problem is with the way Azure handles php artisan optimize.

Looking at the Kudu process explorer, when using the standard php artisan optimize post-install-cmd, there ends up being a load of PHP processes:-

cmd.exe {path}\deploy.cmd

php.exe composer install {options}

cmd.exe php artisan optimize

php.exe php artisan optimize

cmd.exe composer dump-autoload --optimize

php.exe composer dump-autoload --optimize

So, there ends up being three PHP processes running at the same time and the whole thing seems to grind to a crawl (e.g. 20 minutes to compile on a dual-core instance... single core never finished; even the quad-core instances run this extremely slowly compared with running it on my own machine).

After the change described by @22media above, the optimized deployment now takes a minute or so on a dual-core instance, with fewer processes running. Much, much better:

cmd.exe {path}\deploy.cmd

php.exe composer install {options} --optimize-autoloader

cmd.exe php artisan optimize

php.exe php artisan optimize:classes

1 like

Please or to participate in this conversation.