open source

All my posts about open source.

Improving the performance of our PHP based crawler original

by Freek Van der Herten – 2 minute read

Today a new major version of our homegrown crawler was released. The crawler is used to power our http-status-check, laravel-sitemap and laravel-link-checker packages. A new major feature is the greatly improved crawling speed. This was accomplished by leveraging multiple concurrent requests. Let's…

Read more

Laravel service provider examples

On his blog Barry van Veen listed some examples of things you can do within a Laravel service provider.

Currently, I'm working on my first Laravel package. So, it was time to dive into the wonderful world of the service container and service providers.

Laravel has some great docs about, but I wanted to see some real-world examples for myself. And what better way than to have a look at the packages that you already depend on?

This post details the different things that a service provider can be used for, each taken from a real open-source project. I've linked to the source of each example.

https://barryvanveen.nl/blog/34-laravel-service-provider-examples

Read more

Join 9,500+ smart developers

Get my monthly newsletter with what I learn from running Spatie, building Oh Dear, and maintaining 300+ open source packages. Practical takes on Laravel, PHP, and AI that you can actually use.

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

How to open source at Zalando

Zalando, a large online fashion plaform, published it's guidelines around open source creation and usage.

Why Open Source? Because it can: improve quality, mitigate risk, increase trust, save us money, expand our technology choices, be fun, enable us to give back to the community, strengthen our tech brand, and attract talent. ... Do “Open Source First”: If your Zalando project can also be useful to non-Zalandos, release it as open source from the start.

https://github.com/zalando/zalando-howto-open-source

Read more

An opinionated tagging package for Laravel apps original

by Freek Van der Herten – 4 minute read

There are a lot of quality tagging packages out there. Most of them offer the same thing: creating tags, associating them with models and some functions to easily retrieve models with certain tags. But in our projects at Spatie we need more functionality. Last week we released our own - very…

Read more

How I open sourced my way to my dream

Laravel employee #1, Mohammed Said, recently gave an interview at codeforaliving.io on his career and how he started with open source. Terrific story. A lot of what he says resonates with how I feel about working on open source.

Said believes many developers, in the Middle East and elsewhere, are interested in the open source community, but not sure how to get started: “They think they have to wait until they have something perfect.” That’s simply not the case, Said maintains. He encourages developers to dig deep into their favorite projects, especially into software they work with on a daily basis, and look for places they can offer “enhancements” to existing code.

Open source, he believes, is the best experience a developer can show in an interview. “Tech interviewers want one thing,” he says: “Show me your code.” You can share code you’ve written for your day job, but it’s probably impersonal or boring or even proprietary and closed source, so you can’t share it at all. Some code at work is done as part of a team and you can’t pick out what you did and what Jane down the hall did. Open source, on the other hand, is all you. It’s your passion, it’s publicly accessible, and it has your name on it.

http://www.codeforaliving.io/how-i-open-sourced-my-way-to-my-dream-job-mohamed-said

Read more

A class to parse, build and manipulate URLs original

by Freek Van der Herten – 2 minute read

For several projects and other packages we need to manipulate URL's. Instead of coding the same URL class over and over again, we extracted URL manipulation to it's own package. Here are some code examples on how you can use it. $url = Url::fromString('https://spatie.be/opensource'); echo…

Read more

Managing opening hours with PHP original

by Freek Van der Herten – 2 minute read

For several different clients we needed to display a schedule of opening hours on their websites. They also wanted to display if a department / store / ... is open on the moment you visit the site. My colleague Seb extracted all the functionality around opening hours to the newly released…

Read more

Our packages have been downloaded one million times original

by Freek Van der Herten – 12 minute read

I'm very happy to announce that, as of today, our Laravel and PHP packages have been downloaded a million times. We now have more than 80 packages registered on Packagist. All combined they are downloaded around 150 000 times a month, and that number seems to be growing. Our GitHub organisation has…

Read more

The MIT License, Line by Line

Kyle E. Mitchell goes over the MIT License, line by line.

If you’re involved in open-source software and haven’t taken the time to read the license from top to bottom—it’s only 171 words—you need to do so now. Especially if licenses aren’t your day-to-day. Make a mental note of anything that seems off or unclear, and keep trucking. I’ll repeat every word again, in chunks and in order, with context and commentary. But it’s important to have the whole in mind.

https://writing.kemitchell.com/2016/09/21/MIT-License-Line-by-Line.html

Read more

Automatically generate a sitemap in Laravel original

by Freek Van der Herten – 7 minute read

Today my company released a package called laravel-sitemap. There are already a lot of excellent sitemap packages out there. They all have in common that you have to manually add links that must appear in the sitemap. With our new package that isn't required. It can automatically build up a sitemap…

Read more

A package to easily work with regex in PHP original

by Freek Van der Herten – 2 minute read

PHP offers some functions to work with regular expressions, most notably preg_match, preg_match_all and preg_replace. Unfortunately those functions are a bit hard to use. Take preg_match_all for example, it requires you to pass in an array by reference to get all the matches. When something goes…

Read more

Joind.In Needs Help

Joind.in is a website where attendees can leave feedback for speakers delivering talks and conferences and user groups. This feedback is very useful for the speakers who which improve their skills. In my mind it is an essential part of the PHP ecosystem.

For the last 6 years Lorna Jane Mitchell and Rob Allen have maintained the project. They are now looking for others to take over their duties.

This post is about the open source project, Joind.in. Joind.in is a tool to allow attendees at conferences or other events to offer immediate public feedback to speakers and organisers at those events. Joind.in is an open source project run by volunteers. For the last 6 years I've been a maintainer of this project, following a year or two of being a contributor. Over the last few months, myself and my comaintainer Rob Allen have been mostly inactive due to other commitments, and we have agreed it's time to step aside and let others take up the baton.

http://lornajane.net/posts/2016/joind-in-needs-help

Read more

moment().endOf(‘term’)

Without any doubt Tim Wood, the creator of the awesome moment.js library, has done a lot for the community. It's really a shame that the constant pressure of maintaining the library has taken it's toll.

The correlation between Open Source and burnout is no secret, and I am not immune to it. ... Seeing bugs and issues continue to roll in and being mentally unable to address them has led to feelings of failure and depression. When looking at the moment project, I could only see the negatives. The bugs and misnomers and mistakes I had made. It let to a cycle of being too depressed to contribute, which led to being depressed because I wasn’t contributing.

https://medium.com/@timrwood/moment-endof-term-522d8965689

Read more

Our packages are now postcardware original

by Freek Van der Herten – 1 minute read

My company has released a lot of PHP and Laravel packages. According to the packagist stats they have been downloaded for a little over 700 000 times. Up until now they've all been free. That is going to change. Our packages are now postcardware. This means that from now on you are required to send…

Read more

Validating SSL certificates with PHP

With vanilla PHP it's possible to check of if the SSL certificate of a given site is valid. But it's kinda madness to do it. Let's look at the code required:

<br />// Step 1: downloading the certificate from the site
$streamContext = stream_context_create([
    'ssl' => [
        'capture_peer_cert' => true,
    ],
]);

$client = stream_socket_client(
    "ssl://spatie.be:443",
    $errorNumber,
    $errorDescription,
    $timeout,
    STREAM_CLIENT_CONNECT,
    $streamContext);

$response = stream_context_get_params($client);

$certificateProperties = openssl_x509_parse($response['options']['ssl']['peer_certificate']);

// Step 2: parsing the certificate

/*
* I'm not even going to type out the further code needed.
*
* `$certificateProperties` has two keys `validFrom_time_t` and `validTo_time_t`. 
* Those keys contain the UTC representation of the date.
* You will need to check if the current date is between those dates.
*/ 

What. The. Actual. F. Let's fix this!

We've released a new package named spatie/ssl-certificate that makes checking the SSL certificate of a site laughably easy. Let's take a look at the code:

$certificate = SslCertificate::createForHostName('spatie.be');
$certificate->isValid(); // returns true if the certificate is currently valid

Boom, done.

The package has a few more methods that makes working with an SSL certificate a breeze:

$certificate->getIssuer(); // returns "Let's Encrypt Authority X3"

$certificate->getDomain(); // returns "spatie.be"

//A certificate can cover multiple (sub)domains. Here's how to get them.
$certificate->getAdditionalDomains(); // returns ["spatie.be", "www.spatie.be]

$this->certificate->validFromDate(); // returns an instance of Carbon

$certificate->getExpirationDate(); // returns an instance of Carbon

You can also use isValid to determine if a given domain is covered by the certificate. Of course it'll keep checking if the current datetime is between validFromDate and expirationDate.

$this->certificate->isValid('spatie.be'); // returns true
$this->certificate->isValid('laravel.com'); // returns false

The source code of the package is available on GitHub. My company has made many more PHP framework agnostic, Laravel and JavaScript packages in the past. Take a look at the open source page at our site to see if we've made anything that could be of use to you.

Read more

Typo Squatting and Packagist

Jordi Boggiano investigated if there are pundits actively abusing typos in package names.

Earlier this month an article was published summarizing Nikolai Philipp Tschacher's thesis about typosquatting. In short typosquatting is a way to attack users of a package manager by registering a package with a name similar to a popular package, hoping that someone will accidentally typo the name and end up installing your version of it that contains malware.

... I wanted to take a look at our repository data and see if I could spot any bad actors.

https://seld.be/notes/typo-squatting-and-packagist

Read more

A Blade directive to export PHP variables to JavaScript original

by Freek Van der Herten – 1 minute read

Today we released our new package called laravel-blade-javascript. It provides you with a javascript Blade directive to export PHP variables to JavaScript. So it basically does the same as Jeffrey Way's popular PHP-Vars-To-Js-Transformer package but instead of exporting variables in the controller…

Read more

A package to determine which track a last.fm user is playing original

by Freek Van der Herten – 1 minute read

If you've been reading the last couple of posts on this blog then you'll know we're busy building a dashboard. I think it's fair to say that everyone at Spatie is music addict. We have the unwritten rule that whoever who comes in first at the office is DJ for the day. One of the things we'd like to…

Read more

A package to manage events on a Google Calendar original

by Freek Van der Herten – 3 minute read

Like previously mentioned we're currently building a new dashboard to display on our wall mounted TV at the office. One of the things we want to show on that dashboard are important events for our company. Things like when a site goes live, when there's a conference we're going to visit, when we're…

Read more