The folks over at Spatie have released a new tool called Ray that helps you with debugging.
Ray is a beautiful, lightweight desktop app that helps you debug your app. After installing one of the libraries to send information to Ray, you can use the ray() function to quickly dump stuff. Any variable(s) that you pass to Ray will be displayed.
Since Spatie mainly develops with Laravel it plays very nice with it. It supports logging all performed queries or properly displaying the contents of any Eloquent Model / Mailable for example.
In 2004 Vimeo wrote their first backend code in PHP. 16 years later and they (mainly) still run PHP.
Many developers wrote a bit of PHP a decade ago and have since moved on to better-respected languages. They’re often eager to tell others how relieved they are to not be writing PHP anymore, and how it can’t be redeemed.
I’m here to tell you that it can, and Vimeo’s continued success with PHP is proof that it’s a great tool for fast-moving companies in 2020.
The other day the namshi/cuzzle PHP pacakge came in really handy.
This library let’s you dump a Guzzle request to a cURL command for debug and log purposes
This way I could test some things on the CLI, and easily share these tests with all my colleagues, including those without PHP installed.
$request = new Request('GET', 'example.local');
$options = ;
echo (new CurlFormatter())->format($request, $options);
// ~> curl example.local -X GET -A 'GuzzleHttp/6.4.1 curl/7.71.1 PHP/7.4.9'
Also comes with a Monolog formatter to easily log the resulting curl commands in your log files. Do keep in mind that you might be leaking sensitive information (passwords/tokens) that way …
In this post, I’ll present some strategies we use at Tighten to convert legacy apps to Laravel gradually over time, without needing to perform a full rewrite. Whether you’re upgrading from an old framework or moving to a framework for the first time, following these steps will let you start benefitting from all that Laravel has to offer right away.
What they basically do is set up a new Laravel project and have it catch the parts that they changed/added. Using a catchall rule, all other requests are routed to the legacy code. Clever.
Part of a PHP project I’m working contains a list of sites/buildings. For each site/building we monitor some data, for example its energy usage.
We decided that we wanted to generate a daily/weekly/monthly reports of the data, by aggregating the datapoints. As our sites/buildings are spread across the globe – and thus timezones – we can’t simply select data between 00:00:00 UTC and 23:59:59 UTC but have to use its geographical location’s “day window” to do our calculations.
Unfortunately we don’t store the timezone for a site/building, but since we do keep track of its geographical location – using a WGS84 latitude-longitude pair – it should be possible to derive its timezone, right?
// Timezone for one NY coordinate
// ~> America/New_York
// Timezone for one Belgian coordinate
echo get_nearest_timezone(51.0162167, 3.7338451);
// ~> Europe/Brussels
// More faster and accurate if you can pass the country code
echo get_nearest_timezone(40.772222, -74.164581, 'US');
// ~> America/New_York
With this timezone identifier now being available, we can include it in our queries and generate our daily/weekly/monthly reports 🙂
🍻 Here’s to copying-and-pasting from StackOverflow!