Josheli
  • Home
  • Knob
    • Blog
    • Running
    • Soccer
    • Technology
  • Projects
    • Overview
    • Google Photos WordPress Plugin
    • Plex Channels
    • Sh***y Game
    • Soccer In Colorado
    • Statrat
    • The Dot Game
    • Vox cPanel Hacks
    • WW Points Calculator
  • About

Interests

  • Knob
  • Running
  • Soccer
  • Technology

Other Sites

  • Family Vance
  • Texas Longhorns News

Projects

  • Overview
  • Google Photos WordPress Plugin
  • Plex Channels
  • Sh***y Game
  • Soccer in Colorado
  • Statrat
  • The Dot Game
  • Vox cPanel Hacks
  • WW Points Calculator

Social Things

  • Family Photos
  • Juiskie’s Instagram
  • Scooter’s Facebook
  • Scooter’s Instagram
  • YouTube Videos
  • DV’s Github
  • Tweet Tweet
Knob , Technology

Laravel, Composer and Optimize

by dv February 18, 2016 No Comments

So I write these little tech snippets mostly as a personal journal for my future self. Anyway, got caught again at work by a weird situation where dev and test/prod environments differed. Well, not really, but kind of. What?

I deployed our main app last month after upgrading it to Laravel 5 and all seemed to be working fine. Was working fine on dev too. Fast forward to today and my tests break on dev with an error about not finding a couple of namespaced classes. Hour or two of sleuthing ensued.

The gist? By default Laravel runs the command “php artisan optimize” after install and update. This command runs “composer dump-autoload –optimize” behind the scenes. That Composer command generates a huge class map of all of your classes, even your PSR classes… unless you tell it not to (which you can do through the Laravel command by passing the “psr” option).

So on dev, I regularly make changes, add/remove classes, and run “composer dump-autoload” after I do. Notice that command I run manually does not contain the “–optimize” option. Thus the huge class map is not created. Thus the two classes that are somewhat non-standard in their location on disk are not found by the PSR autoloader. Thus the error.

I’m not sure why “composer dump-autoload –optimize” can find and map those two classes just fine, but the actual PSR autoload implementation (without a classmap), cannot find those two classes. But it can’t. And it breaks.

So as a final result, I need to remember to add the –optimize flag when I run dump-autoload on dev (because that’s what Laravel does on test/prod). Or I could move those two classes somewhere else, or add their location to the “classmap” key in my composer.json.

Clear as crystal?

Related Content:

  • Automated Testing with Codeception by Dv February 12, 2016 I gave a little presentation at work the other day on using automated testing in my Laravel project using Codeception.…
  • Looping back by Dv June 4, 2008 Sorely lacking in the Knob department, but my goal for the immediate future is to at least post short snippets…
  • PHP, JSON, Strings, Integers, Mysqlnd and Matching… by Dv January 29, 2016 Here's another instance of being wary when your development environment does not exactly match your production environment. In PHP, for…
  • Finally by Dv July 2, 2007 Thanks everyone. I'm going to take some time off. Maybe a week, probably a month. I'll swim a bit, bike…
  • Another blog about me plus some other stuff by Dv March 20, 2008 I said "I'm slow." Fletcher said, "save it for the blog." So here it is. I'm slow. By slow I…
  • Previous More Janky Snowboarding Video2 years ago
  • Next Westminster Neighborhood 5K Race Report: It’s Been a Long Time2 years ago

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Popular Posts

  • Josheli, What Happened? (6,126)
  • More Janky Snowboarding Video (3,650)
  • Running a Plex Media Server on an Old Laptop (3,256)
  • Which ruby? (2,300)
  • 2007 Dallas White Rock Marathon (2,150)

Random Read

Bagelfest 5K
That RunTex article I regurgitated in my last post isn't very clear. I finished second…

Read More

Google Photo
Google Photo
Google Photo
Google Photo

RSS From Familyvance

  • Fishing and Hiking at Golden Gate Canyon State Park
  • Rainbow Trout Fishing Report at Waneka Lake
  • Weightless Texas-Rig Plastic Worms at Sawhill Ponds and Coot Lake
  • Sawhill Ponds Fishing Report
  • Sandstone Ranch Fishing Report
2018 Josheli. Donna Theme powered by WordPress