31 August, 2023 by Yoan Arnaudov
• Category: Cloudflare
Cloudflare is a great free tool that offers static asset caching out of the box. You can also cache dynamic pages with it, which is quite handy.
Caching things is nice, but invalidating the cache is not a fun business.
There is this popular quote:
There are only two hard things in Computer Science: cache invalidation and naming things.
-- Phil Karlton
I've done a little experiment with Cloudflare. I've configured caching in my blog. The post you are reading right now is cached in CF, currently with a TTL (Time to live) of 1 day.
After configuring the cache, a question immediately arose in my mind. If I update an article I'll need to wait for the cache to expire before the modifications become visible to the public, which is not ideal. I want immediate updates, but then I also want caching.
So what is the solution? Simple - invalidate the cache each time the blog post is updated. Thankfully, Cloudflare offers free API, which allows you to do just that - purge cached content by URL. The documentation is not quite clear, and the method I've used is not documented 🤔, but it works, trust me.
30 August, 2023 by Yoan Arnaudov
• Category: Symfony
The Symfony DomCrawler component is a powerful tool within the Symfony framework for web scraping and HTML/XML parsing. It provides a convenient and intuitive API for traversing and manipulating HTML or XML documents, making extracting specific elements, attributes, and text from web pages easier.
In the realm of modern data handling, Elasticsearch has emerged as a powerhouse, offering rapid data search and analysis.
As a PHP developer, integrating this robust search engine into your projects can elevate your data operations to new heights. In this article, we'll illustrate a concise example of how to create an index, create a document, get a document, and search for documents using PHP's cURL library.
The following examples will empower you to efficiently store, retrieve, and manipulate data through Elasticsearch's RESTful API, all within the familiar PHP environment.
26 August, 2023 by Yoan Arnaudov
• Category: Symfony
I've decided to test the performance of two popular PHP frameworks - Laravel and Symfony. The results surprised me.
The performance test which I've conducted is quite simple. I've created two projects in Symfony and Laravel with only one page, no database queries, no API calls, and no complex calculations, just one simple page. Then I ran HTTP stress tests using a benchmarking tool against both setups and the results are surprising.
Did you know that Laravel uses a lot of Symfony components under the hood?
Symfony is known for making really good components used across the whole PHP ecosystem in numerous packages. Most of the Symfony components can be used as a standalone package without the need for Symfony itself, which is quite handy.
For example, the laravel/framework packages uses 11 Symfony components (at the time of writing this post), some of which are symfony/routing, symfony/mailer, symfony/http-foundation etc.