Posts tagged with github

Automatically close stale issues and pull requests

by Freek Van der Herten – 5 minute read

At Spatie we have over 180 public repositories. Some of our packages have become quite popular. We're very grateful that many of our users open up issues and PRs to ask questions, notify us of problems and try to solve those problems, ... Most of these issues and PRs are handled by our team. But…

Read more

Join thousands of developers

Every two weeks, I share practical tips, tutorials, and behind-the-scenes insights from maintaining 300+ open source packages.

No spam. Unsubscribe anytime. You can also follow me on X.

Some interesting numbers about the PHP GitHub repos in 2017

Marcel Pociot, author of BotMan, used GitHub and Google BigQuery to look up some interesting numbers about the PHP repos in 2017.

It's this time of the year again - the end of the year is coming up fast, so why not step back and take a look at what we, as a PHP community, have achieved this year?

For these statistics, I used the free GitHub Archive data in combination with Google BigQuery, which lets you process 1TB of data per month free of charge.

So let's take a look at some numbers.

http://marcelpociot.de/blog/2017-12-21-a-php-year-in-review

My team is mentioned in the article too. Pretty proud of this!

As you can see, Spatie - a company doing a ton of open source projects - is on this list 16 times. Well done ???? !

Read more

Make git work better with GitHub

by Freek Van der Herten – 1 minute read

A few months ago I installed a command line utility called hub. I'm really fond of it. It's aim is to make it easier to interact with GitHub from the commandline. It's a wrapper around the standard git command. Once it's installed you can do stuff like this (take from the manual page) # clone your…

Read more

How I Got From 0 to 1 000 Stars on GitHub in Three Months With My Open Source Side Project

Ondřej Mirtes, author of PHPStan lists some great tips to make a side project succesful.

Most developers have side projects. That's how we try out new things or make something that we miss on the market or in our dev stack. But most side projects end up unfinished and never actually see the light of day. And even if a developer builds up the courage to show his work to the public, he quickly finds out that just publishing a repository doesn't actually bring the masses to his doorstep. ... In this article, I'd like to share with you what I did to make sure that the project doesn't end up in the dustbin of history. I will concentrate on open source software, but the following advice may as well apply to any creative endeavour.

https://medium.com/@ondrejmirtes/how-i-got-from-0-to-1-000-stars-on-github-in-three-months-with-my-open-source-side-project-8ffe4725146#.211n6vihd

Read more

How to contribute to an open-source GitHub project using your own fork

Serial blogger Matt Stauffer wrote a good tutorial on how use forked repos.

I just recently joined a new open source project, and there were a few folks on the team who weren't familiar with how to contribute to an open source project by forking your own copy, so I wrote this up for the docs of that project. I figured I'd also share it here.

If you join a new open source project, it's very likely that you won't get direct access to push commits or branches up to the repository itself. So, instead, you'll fork the repo, make the changes on your version of the repo, and then "pull request" your changes back to the original.

Here are the steps to take.

https://mattstauffer.co/blog/how-to-contribute-to-an-open-source-github-project-using-your-own-fork

Read more

Quickly open a GitHub page from your terminal

At Spatie we use GitHub for both our client projects as our open source code. So in our day to day work we often have to open the browser to view issues of a repo or review pull requests.

Paul Irish, a well known developer and part of the Google Chrome team at Google, made a nice bash script to quickly open up a GitHub page from your terminal. If you're on a path inside a git repo and type "git open" that'll open up the corresponding page on GitHub.

The command also supports, amongst others, repos hosted on GitLab.com and Bitbucket.

https://github.com/paulirish/git-open

Read more

Using Github authentication for login with Laravel Socialite

Laravel hero Matt Stauffer has a new article on his blog where he talks about using a social network site login as the primary login for your application.

Laravel's Socialite package makes it simple to authenticate your users to Facebook, Twitter, Google, LinkedIn, GitHub and Bitbucket. You can authenticate them for the purpose of connecting their pre-existing user account to a third-party service, but you can also use it as your primary login mechanism, which we'll be talking about here.

I'm working on a new little micro-SaaS that is purely dependent on GitHub in order to operate, so there's no reason to set up any user flow other than just GitHub. Let's do it.

https://mattstauffer.co/blog/using-github-authentication-for-login-with-laravel-socialite

Read more

Laravel-medialibrary hits version 3

by Freek Van der Herten – 3 minute read

Not a month has gone by since v2 of the laravel-medialibrary package got released. If you're not familiar with it: the package provides an easy way to associate files with Eloquent models. Though I was quite happy with the improvements made over v1 there were some things that bothered me. Take a…

Read more

Using enums instead of class constants

I've been enums lately instead of relying on class constants. The myclabs/php-enum package provides a nice implementation. The readme lists the benefits of doing so:

Using an enum instead of class constants provides the following advantages:
  • You can type-hint: `function setAction(Action $action) {`
  • You can enrich the enum with methods (e.g. `format`, `parse`, …)
  • You can extend the enum to add new values (make your enum `final` to prevent it)
  • You can get a list of all the possible values (see below)
This Enum class is not intended to replace class constants, but only to be used when it makes sense.
Check it out: https://github.com/myclabs/php-enum

 

Read more

Speed up a Laravel app by caching the entire response

A typical request on an dynamic PHP site can do a lot of things. It's highly likely that a bunch database queries are performed. On complex pages executing those queries and hydrating them can slow a site down.

The response time can be improved by caching the entire response. The idea is that when a user visits a certain page the app stores the rendered page. When a second request to the page is made, the app shouldn't bother with rendering the page from scratch but just serve the saved response.

I've made a Laravel package named "laravel-responsecache" that does just that. Installing it is very easy: just add the service provider and facade to the app's configuration. And step two is... there is no step two. In most cases you're done. All successful responses (that is a response with a statuscode in the 200 or 300 range) to a GET-requests will now be cached for a week. If the response of a specific route or controller should never be cached middleware can be added that prevents caching. Furthermore each logged in user will have have it's own separate cache. Cached responses can be stored in any configured repository in Laravel. You could easily share a cache between servers by using memcached.

I think that behaviour will suit a lot of use cases. If you need some other caching behaviour (eg. cache error responses, exempting redirects, using a common cache for users with the same role, changing the expiration time of the cache) you can easily write a custom caching profile.

The package isn't supposed to sweep performance troubles under the rug. All apps should be optimized so that they'll respond in an acceptable timeframe without using response caching. My rule of thumb is that typical pages in a cms should be able to render within a second (and preferably much less). Anything above that is unacceptable. That number is by no means scientific. Make up your own mind what an acceptable responsetime should be. Of course all of this depends on the type of site and the amount of visitors it has to handle. Also keep in mind that that there are a lot of other aspects that need to be considered when trying to deliver a speedy experience.

There are some great alternatives to cache responses. Two well known solutions are Varnish and Nginx caching. They take response caching one step further by not even invoking php when serving a cached request. Both options are very robust and can work on any scale. The benefits the Laravel package has over Varnish-like solutions is that it is easier to set up and that application logic can be used to determine what needs to be cached.

If you're interested in speeding up your Laravel app using the package, go take a look at it on GitHub:

https://github.com/spatie/laravel-responsecache

Read more

Convert a pdf to an image using PHP

by Freek Van der Herten – 1 minute read

Converting a pdf to an image is easy using PHP, but the API kinda sucks. $imagick = new Imagick('file.pdf[0]'); $imagick->setImageFormat('jpg'); file_put_contents($pathToImage, $imagick); The pdf-to-image-package aims to fix that. Here is the equivalent code: $pdf = new…

Read more

A trait to optionally abort a Laravel app

by Freek Van der Herten – 1 minute read

Inspired by Edd Man's post on optional value control-flows I made a small Laravel package to optionally abort your application. The package provides a Spatie\OrAbort\OrAbort-trait that can be used on any class you want. All the methods of the class will gain orAbort-variant. When the original…

Read more

A Laravel package to easily add paginated routes

by Freek Van der Herten – 1 minute read

Laravel offers a nice way to add pagination. As far as your routes are concerned you don't have to do a thing. It just works out of the box. Unfortunately the generated url's are pretty ugly: http://example.com/news?page=2 What we want are url's that look like this: http://example.com/news/page/2…

Read more

Get data from Google Analytics on legacy sites

Nearly all greenfield projects at Spatie are built with Laravel. A few months ago I made laravel-analytics, a package to fetch data from Google Analytics.

Spatie exists for more than ten years so there are quite a few legacy projects as well. In those projects there is also a need to display some analytics data in the admin-section. Recently Google retired some of their older API's. Unfortunately our old solution to fetch GA data stopped working.

To resolve this problem my colleague Sebastian created a framework agnostic version of laravel-analytics that works with PHP 5.3. If you also have a legacy project that needs some data from Analytics, you can install the package via composer.

Read more

Creating packages

by Freek Van der Herten – 2 minute read

Prosper Otemuyiwa recently wrote an article on how to create Laravel 5 packages on his blog. Although his approach is entirely valid and may suit you well, I work a little differently when creating a new package. First, I create a new GitHub repository where the package will live. In that repo I…

Read more