Spark & Storage

I’ve been wanting to start blogging more frequent development updates and now is a great time to start!

This week I added profile photo upload / management to Spark. Adding this feature forced me to dig into Laravel’s Flysystem integration and file upload classes a little bit more than I have in the past, since both Forge and Envoyer do not accept any uploads.

One process I simplified is retrieving the URL for a file that has been publicly stored in the Flysystem. For the AWS adapter, this is a fairly simple task since the AWS SDK exposes a method to retrieve the URL.

However, for the local adapter, we have not had any convention for where user uploads should be stored. Furthermore, storing user uploads inside the public directory does not play nicely with zero downtime deployment solutions like Envoyer.

When using deployment systems like Envoyer, an entirely fresh copy of the repository is installed with each deploy and the storage directory is attached to a permanent storage directory using a symbolic link. If you store your user uploads in public, they will all go missing on your subsequent deployment. The solution is to store the uploads in your persistent storage directory and then create a symbolic link from your public directory to your storage directory during your deployment process.

Before yesterday, there was no conventional place to store these user uploads other than “anywhere you want within the storage directory”. After reviewing a few libraries in other languages, it became apparent that there would be great benefit to designating a standard location within the storage directory for files intended to be publicly accessible. So, I created the storage/app/public directory in the Laravel repository so that it will be present on all future installs of Laravel 5.2.

Having a standard location within storage for publicly accessible files allows package developers and service maintainers to make your life convenient. For example, in Envoyer, I plan to soon add an automatic hook to create a symbolic link from public/storage to storage/app/public without any manual configuration from users. This will make it a breeze to share user uploads across deployments without remembering to configure a custom deployment hook to build symbolic links.

I have also updated the default filesystems.php configuration file to include a public disk which stores files relative to storage/app/public so that you can easily start storing your files with simple, expressive syntax:

Storage::disk('public')->put($file, $contents);

I hope this will make your Laravel development life a little easier!

How Lumen Is Benchmarked

I’ve received a few tweets asking me to demonstrate how Lumen is benchmarked against Silex and Slim.

First, I should state that all of these frameworks are faster than you will ever need out of the box. Keep in mind that even full-stack Laravel 5.0 powers sites that receive 15,000,000 unique visits per day.

The benchmarks themselves are actually really simple. I use a Homestead VM since that is something anyone can recreate. In my tests, I allocated 2GB of RAM to the machine. Of course, benchmark numbers are going to vary depending on the hardware of your host machine. I personally am running benchmarks on a 2012 Macbook Pro Retina 15″ with 16GB of RAM. So, don’t be surprised if your numbers are different than my numbers.

So, to get started, clone down a copy of each project. I used Slim 3, which is the develop branch of the Slim repository since it is close to release and utilizes the new PSR-7 standard for HTTP. It should be noted that Slim 3 benchmarks a bit slower than Slim 2. In my tests, Slim 2 and Lumen are fairly close, with Slim 2 averaging around 1700-1800 requests per second and Lumen averaging around 1800-1900 requests per second. Slim 3 is a little slower at around 1200-1300 requests per second.

So, once you have the projects cloned down and each of them simply returning “Hello World”, you should run “composer dump-autoload –optimize”. This will make a significant improvement in the performance of these frameworks during the test.

I used the simple “Apache Benchmark” program on Homestead which can be installed via “apt-get install apache2-utils”. Once you have installed Apache Benchmark, you can run the test like so:

ab -t 10 -c 10

This will instruct Apache Benchmark to run for 10 seconds with 10 concurrent requests happening.

You should also consider that benchmark numbers can vary depending on the software running on your computer. All three benchmarks in my test video run slower than advertised on the Lumen homepage probably because I am recording video, sound, etc. You will see some improvement in numbers if all other software is closed and your host machine is basically idle.

For the tests in my video the results were

Silex: 950 requests per second

Slim: 1250 requests per second

Lumen: 1700 requests per second

All of these frameworks are ridiculously fast.

Thought Police

Programmers are an interesting bunch – brimming with passion and pride in the shadows of our mansions. They’re beautiful, our mansions of bits and bytes. But, do you know what gets us worked up? The neighbor’s yard – and their kids… Lord knows they need a tutor.¬†They probably don’t even code to an interface. Gross. I mean, it’s dangerous.

It works both ways, right? I’m practical. Those bookworms that won’t stop blathering about the latest architecture or pattern… Just build something already! Stop wasting your time with useless programming trivia and just write some code!

Programmers love policing each other. Heck, humans loves policing each other. We love telling others what to think, what to love, what to hate. We say it all the time, don’t we?

“I mean, they are nice people, but they aren’t like us, you know?”

I’m guilty. How do we stop being judgmental weirdos and start loving people?

Starting Positive

In the past, fishermen have used the color of the morning sky to predict if the day’s weather will be suitable for sailing. Like the fishermen, I’ve found that the day’s beginnings paint a preview of its course. Start positive, and it’s easier to ride the good vibes for the rest of the day.

I asked the Twitterverse how they start the day. Here are a few common responses:

  • Coffee.
  • Exercise.
  • Meditation.
  • Reading A Religious Text.
  • A Good Breakfast.
  • Watching Funny YouTube Videos With Co-Workers.
  • Listening To Relaxing Music.

For me, I’ve found meditation / silence helpful. It’s a time to gather my thoughts and take some deep breaths. Once my mind is clear, it’s easier to approach the day with a positive attitude!

PHP Developers Who Have Inspired Me

Tonight I want to write a quick post and mention a few PHP developers who have inspired me lately. I’ll name them and share a few reflections on how they have inspired me over the past few months.

  • Fabien Potencier (@fabpot) – Fabien is the project leader for Symfony. He manages a very large PHP project, and he does it very well. He’s humble and professional. I want to better imitate those characteristics.

  • Ross Tuck (@rosstuck) – Ross spoke at the recent Laracon in Amsterdam. Watch the video at I’ve thought about his talk many times since. He’s incredibly intelligent, thoughtful, and one of the best speakers in the PHP community.

  • Yitzchok Willroth (@coderabbi) – Yitzchok has become somewhat of a personal advisor to me. He gives thoughtful advice, challenges me, and encourages me with his wisdom.

  • Michelle Sanver (@michellesanver) – Michelle showed Dayle and I around Zurich for a few hours, and recently spoke at Laracon EU. She’s quiet, but ridiculously smart. She’s building a really cool project called OmNomHub – it’s like GitHub for recipes.

  • Kayla Daniels & Ed Finkler (@kayladnls – @funkatron) – Both of these talented developers are raising awareness of mental illness, and encouraging those suffering to seek the treatment they need for healing. Mental illness is one of the most debilitating diseases on the planet, and I really appreciate the work these developers are doing to combat it.

  • Igor Wiedler (@igorwhiletrue) – Igor is always doing something cool things that twist my brain. He’s very humble, and an all around nice guy. I always enjoy reading over his latest code.

  • Mior Muhammad Zaki (@crynobone) – Mior and I talk about Laravel a lot. He listens to a lot of ideas and helps me sharpen them. He lives on the bleeding edge of Laravel quietly making sure everything is up to snuff – and never complains about anything.

  • Matt Stauffer (@stauffermat) – Matt is a great friend. He gives great technical advice about Laravel. But, more than that, he gives me great life advice.

  • Konstantin Kudryashov (@everzet) – Konstantin is way smarter than me. He recently spoke at Laracon EU and gave me great feedback for improving areas of Laravel 5. One day I want to write code like Konstantin!

Of course, there are so many other awesome PHP developers out there, and so many of you have impacted me in a positive way. Maybe I’ll do one of these posts every month to keep spreading the love!