PHP & Web Development Blogs

Search Results For: offer
Showing 1 to 5 of 18 blog articles.
9029 views · 5 years ago
When PHP Frameworks Suck

INTRO

If you are working as a PHP software developer, there is an extremely high chance that all of your application, you’re currently working on, using frameworks of any kind.
PHP community developers of all levels worship frameworks since there are big historical and practical reasons for that.

Historical reasons

Since early PHP versions, developers were disreputable because not everybody considered PHP as a programming language, similar to JavaScript a couple of years ago. While strong type language existed decades ago, PHP continues to be soft type since now, only in version 7 basic types were introduced. There is also a matter of the fact that you can script in PHP without using a single object.

But that opened a space for frameworks to step in and introduce themselves as a tool or standard which will shape projects, give them right and order, introduce structure and rules.
And finally, they did. Frameworks are good examples of nice structures, using all available new features PHP offers with every version, enforcing some good practice, etc.

Practical reasons

The framework offers a lot of common problems already solved. They offer a nice ecosystem for other developers to contribute and plug their components. There is a lot of online resources for learning and stay updated about any particular framework. Also, what every framework community tries very hard, is to make setup and usage easy.

WHEN PHP FRAMEWORKS SUCKS

I recently had the opportunity to give a talk on a conference and one meetup about why PHP framework sometimes sucks. Sometimes things we see in framework tutorials does not seem to be very much aligned with some object-oriented standards we are striving to enforce, and with basic clean code guidelines. On the other hand, there is nothing wrong with using a framework, if you use it right.

This article is the first "pilot" article in this series. In every new blog in this series, we will go more in-depth about every specific topic I covered during my presentation.
I'm very excited to share this knowledge, as I saw many developers suffer from bonded-to-framework disease.

https://twitter.com/damnjan/status/1058306144458956800

I won’t spend much time here on any particular framework discussion. This series will be just a guide on how to unbind yourself from frameworks and use them as a tool, instead of being independent.

**Here is the link to the presentation slides.**
23008 views · 2 years ago
Is PHP a dying language

It seems like this question gets asked every year, as for some reason the perception surrounding PHP is that it is a language used by hobbyists, or a dying language - a programming language on its way out.

Before we take a look at "is PHP being used less," let's start with some critical points to consider when choosing a programming language to learn/ invest in.

PHP powers ~80% of the web


The first point is how popular PHP is as a program language. Recently in a podcast a debate around PHP was raised, with the question being is it an "enterprise" language. The argument against PHP is that it is not widely adopted by enterprises for enterprise application development - or apps that are traditionally developed in Java or .Net.

The key here is understanding that every tool has its strengths and weaknesses, and there are times where using a compiled language such as Java is a smarter move than using PHP. As always, you want to choose the right tool for the job, and PHP as a programming language excels for web applications. That's why today it powers nearly 80% of the websites on the internet! I want to repeat that number, nearly 80% of websites on the internet!

In the podcast, after the initial argument that PHP was not an enterprise language, I had one question to ask - "can you name one enterprise that doesn't use PHP?" Despite the misconception that PHP is not an enterprise language, nearly every enterprise utilizes PHP in some fashion (many for their website, blog, or internal tools). While PHP may not power the app they offer as a service (although for many companies it does), it powers just as critical of offerings that help drive success for the company.

PHP made Yahoo, Facebook, and Tumblr possible


It's not just personal blogs running on a WordPress install, or small sites running on Drupal (btw, both of these power high traffic, well known web properties), but PHP actually makes development for the web easier and faster. Because it is not a compiled language and is designed to scale, companies are able launch faster, add new features as they go, and grow to enormous scale.

Some of the sites that started with PHP include Yahoo, Facebook, Tumblr, Digg, Mailchimp, and Wikipedia! But it's not just older platforms that started off and have grown to scale with PHP - Etsy, Slack, Baidu, Box, and Canva also got started with PHP! Read why Slack chose PHP

In fact, according to BuiltWith, PHP powers 53.22% of the top 10k websites!

Programming languages don't just disappear


Understanding the prevalence of PHP today, and how often it is used is critical to understanding the longevity of PHP. Despite the radicalized idea, programming languages (and thus programming jobs) do not just disappear overnight. Today you can still find jobs writing code used in mainframes - such as Fortran or Cobol.

As long as companies have applications that use PHP, they'll need someone who knows PHP to maintain the application. And with PHP actively being developed and maintained (PHP 8 having just been released), and PHP powerhouses like WordPress, Drupal, SugarCRM, and others powering websites and apps around the world, it's a safe bet PHP won't be going anywhere anytime soon.

But with the basics out of the way, let's look at how PHP has faired over the years.

PHP usage over the years


While there is no exact measurement that determines how programming languages are ranked, there are several different rankings we can look at to see how a language has evolved over the years, and where it ranks today.

GitHub's most popular programming languages


Every year GitHub releases a report of the most popular languages being used to create repositories on GitHub.com. While this isn't an exact way to quantify a programming language, it does help us understand what languages developers are using and promoting for their applications. It also helps us see how lively the community itself is.

In 2014, PHP was ranked as the 3rd most popular programming language, being beat out only by JavaScript and Java. With the emergence of Typescript, C# moving open source, and increased usage of Python for AI - PHP did drop - and was the 6th most popular programming language on GitHub for 2020.

PHP on GitHub over the years

PHP's ranking on the Tiobe index


Another index for software popularity is the Tiobe index, which bases their ratings off of the number of search engines for programming languages. This index is heavily relied on by companies when making programming and investment decisions, especially in developer marketing.

Like with GitHub, PHP has also seen a decline in the Tiobe index. Ranked 8th last year for all languages, PHP dropped to 9th place, being outranked by the C languages (C, C#, C++), Java, Visual Basic, Python, JavaScript, and Assembly. However, to put the rankings in contrast, PHP is 9th out of the 274 languages Tiobe tracks, and bests SQL, Ruby, Groovy, Go, and Swift.

You can see the latest Tiobe index (updated monthly) at: https://www.tiobe.com/tiobe-index/

PHP's ranking on BuiltWith


The last model we'll look at is BuiltWith. BuiltWith scans website headers to determine what a website is powered by, and like GitHub and Tiobe provides a ranking of programming language popularity and trends.

Builtwith provides an interesting perspective in that we can see an explosion of sites being built with PHP (nearly tripling from 2013 to 2016) before dropping and normalizing in 2017. From 2017 to present, the number of sites using PHP has remained almost constant.

BuiltWith PHP Usage

This suggests (as with what we've seen with GitHub and Tiobe) that other languages have grown in popularity, such as JavaScript and Node.js. This doesn't mean that PHP is no longer being used or relied or, but rather that there is more competition and that there are other viable options whereas PHP stood alone at times in terms of being the goto language for web development.

Indeed, when we look at how PHP ranks amongst all technologies on BuiltWith, PHP receives the following BuiltWith awards:

• The most popular on the Entire Internet in Frameworks category.

• The most popular in the Top 10k sites in Frameworks category.

• The most popular in the Top 100k sites in Frameworks category.

• The most popular in the Top 1 Million sites in Frameworks category.

Conclusion


PHP's popularity has dropped from its height 10 years ago, however it still remains the most popular programming language powering the web. It's important to remember that every tool has pros and cons, and some of the bad rap PHP gets is when compared to languages designed to accomplish tasks or build programs that PHP was never designed to.

It's also important to remember a lot of early criticism for PHP came from it being a procedural programming language and not encompassing Object Oriented Programming capabilities. These capabilities were added in PHP 4 and with PHP 7 & 8 OOP has become a staple of the PHP language.

PHP is a viable, powerful language used by nearly every enterprise and many businesses large and small. In fact it powers over 50% of the top 10,000 websites on the web! With such large usage, popular tools such as WordPress, and an active community, it is safe to assume that PHP will remain a prominent language for years to come.
40 views · 2 days ago


In today's dynamic and fast-paced world of web development, ensuring the reliability, performance, and scalability of applications is paramount. Monitoring and observability tools play a crucial role in achieving these goals by providing insights into application metrics, performance trends, and system health. Prometheus, a popular open-source monitoring and alerting toolkit, offers robust capabilities for monitoring infrastructure and application metrics. In this article, we'll explore how to leverage Prometheus with PHP to monitor, analyze, and troubleshoot PHP-based applications effectively.

Understanding Prometheus:


Prometheus is an open-source monitoring and alerting system originally developed by SoundCloud. It is designed for reliability, scalability, and extensibility, making it suitable for monitoring complex, distributed systems. Key features of Prometheus include:

Time Series Data: Prometheus collects time-series data, allowing developers to track metrics such as CPU usage, memory consumption, request latency, and HTTP response codes over time.

PromQL: Prometheus Query Language (PromQL) enables users to query and aggregate metrics, create custom dashboards, and set up alerting rules based on specific conditions.

Scalability and Reliability: Prometheus is designed to be highly scalable and reliable, supporting a distributed architecture with multiple replicas and federated setups for global monitoring.

Integrating Prometheus with PHP:


To integrate Prometheus with PHP applications, developers can utilize client libraries and instrumentation libraries that facilitate metric collection and exposition. The following steps outline the process of integrating Prometheus with PHP:

Choose a Prometheus Client Library: Select a Prometheus client library for PHP that suits your needs. Popular options include prometheus/client_php and php-prometheus/client.

Instrument Your PHP Code: Instrument your PHP application code to collect relevant metrics. This involves adding instrumentation code to track metrics such as request duration, memory usage, database queries, and custom business metrics.

Exposing Metrics: Expose the collected metrics in a format compatible with Prometheus. This typically involves exposing an HTTP endpoint (e.g., /metrics) where Prometheus can scrape the metrics using the Prometheus exposition format.

Configure Prometheus Server: Configure the Prometheus server to scrape metrics from the PHP application's endpoint. Update the Prometheus configuration file (prometheus.yml) to include the target endpoint and define any additional scraping parameters.

Example Integration:


Let's illustrate how to integrate Prometheus with a PHP application using the prometheus/client_php library:

require 'vendor/autoload.php';

use Prometheus\CollectorRegistry;
use Prometheus\Storage\APC;
use Prometheus\RenderTextFormat;

$registry = new CollectorRegistry(new APC());

$requestDuration = $registry->registerCounter('php_requests_total', 'Total number of PHP requests');

$requestDuration->inc();

$renderer = new RenderTextFormat();
echo $renderer->render($registry->getMetricFamilySamples());


In this example, we register a custom metric (php_requests_total) to track the total number of PHP requests. We then increment this metric for each request and expose the metrics endpoint using the Prometheus exposition format.

Benefits of Using Prometheus with PHP:


Real-time Monitoring: Prometheus provides real-time monitoring capabilities, allowing developers to monitor application metrics and diagnose issues promptly.

Scalability: Prometheus scales horizontally, making it suitable for monitoring large-scale deployments and distributed systems.

Alerting: Prometheus supports alerting based on predefined rules, enabling proactive monitoring and alerting for potential issues or anomalies.

Integration: Prometheus integrates seamlessly with various programming languages, platforms, and frameworks, including PHP, enabling comprehensive monitoring across the entire technology stack.

Conclusion:


Prometheus offers powerful capabilities for monitoring and observability, making it a valuable tool for developers and DevOps teams tasked with ensuring the reliability and performance of PHP applications. By integrating Prometheus with PHP using client libraries and instrumentation, developers can gain valuable insights into application metrics, troubleshoot issues effectively, and proactively respond to performance anomalies. Embracing Prometheus as part of your monitoring strategy empowers organizations to build resilient, scalable, and high-performing PHP applications in today's dynamic digital landscape.
51 views · 2 days ago


In the realm of web development, the Model-View-Controller (MVC) architectural pattern stands as one of the most influential paradigms. It provides a structured approach to designing web applications, promoting modularity, scalability, and maintainability. In this guide, we'll delve into the MVC framework in PHP, exploring its key components, principles, and benefits.

Understanding MVC Architecture:


MVC separates an application into three interconnected components, each with its distinct responsibility:

Model: The model represents the application's data and business logic. It encapsulates the data structure, database interactions, and validation rules. In MVC, the model is responsible for managing data persistence and state.

View: The view is responsible for presenting data to the user in a visually appealing format. It encompasses the HTML markup, CSS styling, and client-side scripting necessary to render the user interface. Views are typically passive components that receive data from the controller and display it to the user.

Controller: The controller acts as an intermediary between the model and the view. It processes user requests, invokes the appropriate methods in the model to retrieve or manipulate data, and selects the appropriate view to render the response. Controllers handle user input, orchestrate business logic, and coordinate the flow of data between the model and the view.

Implementing MVC Framework in PHP:


PHP offers a robust foundation for building MVC-based web applications. Let's explore how to implement each component of the MVC pattern in PHP:

Model:


In PHP, models typically represent data entities and interact with the database. They encapsulate data access logic and provide methods for querying, inserting, updating, and deleting records. Here's a simplified example of a model class:


class User {
public function getUserById($userId) {
}

public function updateUser($userId, $userData) {
}

}


View:


Views in PHP are responsible for generating HTML markup to render the user interface. They receive data from the controller and use it to dynamically generate the content displayed to the user. Views can include HTML templates with embedded PHP code or utilize template engines for better separation of concerns. Here's a basic example of a view:


<!DOCTYPE html>

<html>

<head> <title>User Profile</title>

</head>

<body> <h1>Welcome, <?php echo $user['username']; ?>!</h1> <p>Email: <?php echo $user['email']; ?></p>

</body>

</html>


Controller:


Controllers in PHP handle user requests, process input data, and interact with models to retrieve or manipulate data. They select the appropriate view to render the response and pass data to the view for presentation. Controllers are responsible for defining application routes and managing the overall application flow. Here's an example of a controller method:


class UserController {
public function profile($userId) {
$userModel = new User();
$userData = $userModel->getUserById($userId);

include 'views/profile.php';
}
}


Benefits of MVC Framework in PHP:

Separation of Concerns: MVC promotes a clear separation of concerns, making it easier to manage code complexity and maintainability.

Modularity: Components in MVC are modular and reusable, allowing developers to build and extend applications more efficiently.

Testability: With distinct components, it becomes easier to write unit tests for models, views, and controllers independently.

Scalability: MVC facilitates the scalability of web applications by enabling developers to add new features or modify existing ones without impacting other parts of the system.

Conclusion:


The MVC framework in PHP provides a robust architectural pattern for building scalable and maintainable web applications. By separating concerns into models, views, and controllers, developers can organize code more effectively, enhance testability, and streamline the development process. Whether you're building a simple blog or a complex enterprise application, leveraging the MVC pattern in PHP can significantly improve the quality and maintainability of your codebase.
17 views · 2 days ago


In modern software architecture, developers are constantly exploring new paradigms to enhance the performance, scalability, and maintainability of their applications. One such architectural pattern gaining popularity is Command Query Responsibility Segregation (CQRS). CQRS separates the responsibility of handling read and write operations, offering numerous benefits in complex systems. In this article, we'll delve into CQRS and explore its implementation in PHP.

What is CQRS?


CQRS, coined by Greg Young, is an architectural pattern that segregates the responsibility for handling read and write operations in a system. In traditional CRUD-based architectures, the same model is often used for both reading and writing data. However, CQRS advocates for a clear distinction between commands (write operations that modify state) and queries (read operations that retrieve data).

Key Concepts of CQRS:
   

. Command: Commands represent actions that modify the state of the system. They encapsulate the intent to perform an operation, such as creating, updating, or deleting data.
   
. Query: Queries retrieve data from the system without modifying its state. They are read-only operations used to fetch information for presentation or analysis.
   
. Command Handler: Responsible for processing commands by executing the necessary business logic and updating the system's state accordingly.
   
. Query Handler: Handles queries by retrieving data from the appropriate data source and returning the results to the caller.
   
. Separate Models: CQRS often involves maintaining separate models for commands and queries. This allows each model to be optimized for its specific use case, leading to improved performance and scalability.

Implementing CQRS in PHP:


Implementing CQRS in PHP involves structuring your application to separate command and query responsibilities effectively. Here's a high-level overview of how to implement CQRS in PHP:

1. Define Commands and Queries:


Start by defining the commands and queries your application will support. Commands should encapsulate actions that modify state, while queries should retrieve data.

class CreateProductCommand {
public $name;
public $price;
}

class GetProductQuery {
public $productId;
}


2. Create Command and Query Handlers:


Next, implement handlers for processing commands and queries. Command handlers execute the necessary business logic to fulfill the command, while query handlers retrieve data based on the query criteria.

class CreateProductCommandHandler {
public function handle(CreateProductCommand $command) {
}
}

class GetProductQueryHandler {
public function handle(GetProductQuery $query) {
}
}


3. Use Separate Models:


Maintain separate models for commands and queries to optimize each for its specific purpose. This separation allows you to design models tailored to the needs of write and read operations.

class Product {
public $name;
public $price;
}

class ProductView {
public $name;
public $price;
}


4. Wiring Everything Together:


Finally, wire up your command and query handlers to the appropriate endpoints or controllers in your application. Dispatch commands to their respective handlers and invoke query handlers to retrieve data.

$command = new CreateProductCommand();
$command->name = "Example Product";
$command->price = 99.99;

$handler = new CreateProductCommandHandler();
$handler->handle($command);

$query = new GetProductQuery();
$query->productId = 123;

$handler = new GetProductQueryHandler();
$product = $handler->handle($query);


Benefits of CQRS in PHP:


-Improved Scalability: Separating read and write operations allows you to scale each independently based on demand.

-Enhanced Performance: Optimizing models and handlers for specific tasks can lead to improved performance and responsiveness.

-Simplified Maintenance: Clear separation of concerns makes the codebase easier to understand, maintain, and extend over time.

-Flexibility: CQRS enables flexibility in choosing the most suitable data storage and retrieval mechanisms for different use cases.

Conclusion:


CQRS is a powerful architectural pattern that offers numerous advantages for building complex and scalable PHP applications. By segregating command and query responsibilities, developers can achieve better performance, scalability, and maintainability in their systems. While implementing CQRS in PHP requires careful planning and design, the benefits it provides make it a compelling choice for projects requiring high performance and flexibility.

SPONSORS

The Ultimate Managed Hosting Platform