A pro-PHP Rant

Share this article

OK – following on from here and a later comment from Tim (and in fact more this rant from Jonas Maurus);

How about somebody sends me some good pro-PHP rants?

So here’s some pro-PHP ranting…

It’s the execution model

Focused on PHP as an Apache module the two big things are it works and it’s scalable. More to the point no one really has an execution model to compare with it, except perhaps Microsoft with ASP 3.0, which they’ve since abandoned. Before you fly off the handle, think about this one.

Tried to explain the basics a long time ago here – the important thing to take from that (compared to mod_perl / mod_python / mod_* or even “X” application server.) is the interpreter returning to a fresh state after every request (no globals hanging around or otherwise). PHP really is shared nothing. You want scaling? Try here.

Meanwhile, in these days of long tail enthusiasm, other than PHP, you don’t get to hear much about when stuff sucks. Put specifically, don’t bring me your FastCGI unless you’re providing free SMS to go with it, so I can alert myself when it goes down. There are smallish sites I own / run, built on PHP, which I don’t look at for months but are still, magically, running next time I go there – be it impression or not, PHP just keeps on running – restart Apache or reboot and it’s back without sysadmin effort.

Being a little more specific, the execution model PHP gets most testing under is mod_php and CGI, where there’s no “long running scripts” and no need for threads. PHP is optimized to that environment. By contrast Perl, Python and Ruby are general purpose languages and optimized to different requirements. The web is just another platform they support, compared to PHP where the web is the primary platform. The can be expressed in terms of configuration settings like max_input_time and post_max_size – with PHP these problems have had someone thinking about them.

Excellent database support

Lets start with the usual nag here – that PHP doesn’t have a common API for database abstraction. Well that’s always been bogus anyway – SQL itself is rarely portable and writing an application against a specific database requires specific work, so that you’re API happens to be the same as that for some other database is largely irrelevant. That said a common API does make the learning curve easier if you start another project with another DB but PHP’s first priority is to expose “vendor specific” features, like pg_send_query or mysql_unbuffered_query. Put another way, most of PHP’s DB APIs have a one to one relationship with the vendors client API and the benefit there is you don’t lose features or have to fight for them.

That’s not to say you can’t have your DB abstraction cake in PHP – the one I trust most is ADOdb – a native PHP implementation (side note – Python devs may be interested to know John also maintains a Python version of ADOdb). There’s also PDO which is getting there and (I’d argue) something that parallels Perl’s DBI. Should also point out PEAR::DB, PEAR::MDB2 and Creole. And don’t get me started on ORM…

What doesn’t get said is PHP may now have the best (as in most stable and feature complete) across the board db support of any of Perl, Python and Ruby, which, seen from one point of view, makes sense given the number of PHP users. That PHP’s DB support is better than Python’s or Ruby’s that’s probably no news but compared to Perl, was recently surprised to discover that DBI lacks support for Oracle collections, which PHP has. Perhaps that’s just a freak but perhaps not – anyone with experiences to share there?

PHP Arrays

Now the computer scientists typically hate PHP’s arrays, which are both indexed and hashed. Reality is they are not only easy for beginners to get in to, they’re very handy for the web problem (e.g. good fit to ad-hoc XML) and for simple iteration, it’s nice that hashes and indexed arrays unified by common syntax and behaviour. Sure they don’t support everything a computer scientist might want, such as (Python);


points = {}
points[(1,2)] = 2
points[(2,4)] = 4

…but on the web, who cares? You’d hardly ever need something like that and where you do, JPGraph makes life easy enough. Meanwhile performance turns out to be not bad by comparison.

BTW, if you want computer science and PHP, take a look at (current favorite bizarre PHP project) J4P5 (a Javascript intepreter written in PHP). Can come up with endless projects of that nature if you’re interested.

More generally, there’s a virtual web ring (how 90’s) of PHP hate which starts from here. 90% of the criticism you’ll find there is simply irrelevant (one day I’m going to do this in detail, if I can be bothered) – these are either not problems for web development or disappear with PHP’s (rollercoaster) learning curve (e.g. the endless functions in global namespace is irrelevant if you’re writing classes). One day I may also do my own take on why PHP sucks (in the sense of Bjarne Stroustrup and: “There are only two kinds of languages: the ones people complain about and the ones nobody uses”) which I’d expect to be a very different story. Today you’ll have to excuse me for focusing only on the good things.

The SPL Extension

Following on from arrays, this is a big reason to use PHP5 if you’re a programmer. It makes a number of classes of web related problem ridiculously easy to solve and gives you syntactic joy should you want it. Some further reading here, here, here, here and here.

PHP 5(.1) XML Support

One for Tim – XML support in PHP 5(.1) is excellent, thanks to libxml2. And it’s not just that the core parser is good, it’s that you’ve got multiple APIs in PHP to it, namely SAX and it’s faster “invert” XML pull reader, SimpleXML and DOM, as well as the supporting cast of XSLT etc. Of course Python, Perl, Ruby etc. also have libxml2 wrappers but this is still a PHP strength, plus libxml2 has become the core of PHP’s XML capabilities, rather than another alternative.

The stuff that says it works… works

Programmers have obsessions with building better cages for themselves, for the sake of a particular paradigm they believe in. Nothing wrong with that but the road to get there is littered with stuff that was broken or partially complete. For the stuff you need for the web, PHP is already there. That’s not to say there isn’t a bunch of unstable code in PHP – just the stuff you’re typically going to use works.

Put another way, PHP has become predictable, at least for me and anyone willing to travel the learning curve. That means if I need to give projects estimates, for example, I know when I can keep to them. I’ve also found it easy to teach to others – takes about a week to get a programmer able to churn out useful PHP if I can work directly with them. I’d rather trade a (slightly more) verbose syntax and delivering on time against 15 minutes syntactic glory, followed by 10 hours bug hunting and another 15 hours workaround. Luckily not everyone thinks this way or progress would have halted.

Unicode and ICU

Having talking about stuff PHP already has, it’s worth being aware that PHP6 is using ICU as part of it’s “core” – see here, here and here. PHP6 already “exists” under CVS and if it’s resticted to the Unicode changes only, it’s less of a step up than PHP5 and may be here sooner rather than later. You might then be able to argue PHP has better Unicode support than Perl and Python.

Stuck in Little boxes

This is bordering on holy war, which I don’t want. Recently language bickering has been back “in”, and if you take it seriously you might believe Perl, Python and PHP are all dead and there is only Ruby. To me that’s simply Ruby (rightly) jostling for a space alongside the others and it’s best put in perspective here.

Being happy in Perl, Python and PHP these days, watching people cry “This rox, everything else sux” borders between amusing and frustrating. Syntax is only one part of the story. Libraries is, to me, the bigger part – what use is great syntax if you can’t do anything with it or need to spend time re-inventing wheels?

For example Perl is like comfortable slippers on the command line – take me away from Getopt::Long and POD::Usage and get screaming. Little things which matter. And have found Perl capable of pushing big blocks of data around a DB at speeds comparable to SQL*Loader.

Meanwhile have used wxPython in earnest once (book due soon!) – none of the other dynamic languages can compare to it – yes there’s wxPerl, wxRuby (**cough** wxHaskell) and even wxPHP but they’re not mature by comparison – check out Activegrid’s IDE download under “/src/python/wxPythonDemos/ide” – these days we can all write our own IDEs… And Python has the dirty secret of excellent Windows support. If I had time to burn I’d love to take this shell namespace extension demo and the Python libssh2 wrapper and do a GMail drive for scp.

The point is people leap on a language then claim, because it does one thing well, it’s the only tool for everything. It’s really a shame time is being spent on wxRuby / wxPerl or otherwise, given that wxPython is already there. It’s far more of a shame that we’ve invented endless template engines for the web – not just the wasted development time – also the wasted user time in identifying and learning to use them (this stuff drives them to Microsoft). And it’s not just the re-invention – it’s that we not even really sharing ideas or seeing them spread – Jeff nailed templates a long time ago but today you’ll find Ruby developers discussing the pros and cons of curly brackets vs. attribute for templates.

Specific to PHP, if you accept there are some things it actually does well, in particular the execution model, it then becomes more a question of how to get the best out of all worlds. In my view (based on what I’m happy with) that’s Perl at your backend for sysadmin, moving data around etc., Python helping users publish their MS Office stuff and PHP serving it to the world.

Along that lines been looking at Fuse and it’s Python and Perl bindings. Have a very specific interest right now which I guess will tell me how stable this stuff is but, all being well, think there’s potential here for hooking up PHP with Perl and Python, via the filesystem, perhaps in conjunction with libxml2.

In short: PHP’s Schwarz is bigger!

Harry FuecksHarry Fuecks
View Author

Harry Fuecks is the Engineering Project Lead at Tamedia and formerly the Head of Engineering at Squirro. He is a data-driven facilitator, leader, coach and specializes in line management, hiring software engineers, analytics, mobile, and marketing. Harry also enjoys writing and you can read his articles on SitePoint and Medium.

Read Next
Creating Fluid Typography with the CSS clamp() Function
Creating Fluid Typography with the CSS clamp() Function
Daine Mawer
Comparing Full Stack and Headless CMS Platforms
Comparing Full Stack and Headless CMS Platforms
Vultr
7 Easy Ways to Make a Magento 2 Website Faster
7 Easy Ways to Make a Magento 2 Website Faster
Konstantin Gerasimov
Powerful React Form Builders to Consider in 2024
Powerful React Form Builders to Consider in 2024
Femi Akinyemi
Quick Tip: How to Animate Text Gradients and Patterns in CSS
Quick Tip: How to Animate Text Gradients and Patterns in CSS
Ralph Mason
Sending Email Using Node.js
Sending Email Using Node.js
Craig Buckler
Creating a Navbar in React
Creating a Navbar in React
Vidura Senevirathne
A Complete Guide to CSS Logical Properties, with Cheat Sheet
A Complete Guide to CSS Logical Properties, with Cheat Sheet
Ralph Mason
Using JSON Web Tokens with Node.js
Using JSON Web Tokens with Node.js
Lakindu Hewawasam
How to Build a Simple Web Server with Node.js
How to Build a Simple Web Server with Node.js
Chameera Dulanga
Building a Digital Fortress: How to Strengthen DNS Against DDoS Attacks?
Building a Digital Fortress: How to Strengthen DNS Against DDoS Attacks?
Beloslava Petrova
Crafting Interactive Scatter Plots with Plotly
Crafting Interactive Scatter Plots with Plotly
Binara Prabhanga
GenAI: How to Reduce Cost with Prompt Compression Techniques
GenAI: How to Reduce Cost with Prompt Compression Techniques
Suvoraj Biswas
How to Use jQuery’s ajax() Function for Asynchronous HTTP Requests
How to Use jQuery’s ajax() Function for Asynchronous HTTP Requests
Aurelio De RosaMaria Antonietta Perna
Quick Tip: How to Align Column Rows with CSS Subgrid
Quick Tip: How to Align Column Rows with CSS Subgrid
Ralph Mason
15 Top Web Design Tools & Resources To Try in 2024
15 Top Web Design Tools & Resources To Try in 2024
SitePoint Sponsors
7 Simple Rules for Better Data Visualization
7 Simple Rules for Better Data Visualization
Mariia Merkulova
Cloudways Autonomous: Fully-Managed Scalable WordPress Hosting
Cloudways Autonomous: Fully-Managed Scalable WordPress Hosting
SitePoint Team
Best Programming Language for AI
Best Programming Language for AI
Lucero del Alba
Quick Tip: How to Add Gradient Effects and Patterns to Text
Quick Tip: How to Add Gradient Effects and Patterns to Text
Ralph Mason
Logging Made Easy: A Beginner’s Guide to Winston in Node.js
Logging Made Easy: A Beginner’s Guide to Winston in Node.js
Vultr
How to Optimize Website Content for Featured Snippets
How to Optimize Website Content for Featured Snippets
Dipen Visavadiya
Psychology and UX: Decoding the Science Behind User Clicks
Psychology and UX: Decoding the Science Behind User Clicks
Tanya Kumari
Build a Full-stack App with Node.js and htmx
Build a Full-stack App with Node.js and htmx
James Hibbard
Digital Transformation with AI: The Benefits and Challenges
Digital Transformation with AI: The Benefits and Challenges
Priyanka Prajapat
Quick Tip: Creating a Date Picker in React
Quick Tip: Creating a Date Picker in React
Dianne Pena
How to Create Interactive Animations Using React Spring
How to Create Interactive Animations Using React Spring
Yemi Ojedapo
10 Reasons to Love Google Docs
10 Reasons to Love Google Docs
Joshua KrausZain Zaidi
How to Use Magento 2 for International Ecommerce Success
How to Use Magento 2 for International Ecommerce Success
Mitul Patel
5 Exciting New JavaScript Features in 2024
5 Exciting New JavaScript Features in 2024
Olivia GibsonDarren Jones
Tools and Strategies for Efficient Web Project Management
Tools and Strategies for Efficient Web Project Management
Juliet Ofoegbu
Choosing the Best WordPress CRM Plugin for Your Business
Choosing the Best WordPress CRM Plugin for Your Business
Neve Wilkinson
ChatGPT Plugins for Marketing Success
ChatGPT Plugins for Marketing Success
Neil Jordan
Managing Static Files in Django: A Comprehensive Guide
Managing Static Files in Django: A Comprehensive Guide
Kabaki Antony
The Ultimate Guide to Choosing the Best React Website Builder
The Ultimate Guide to Choosing the Best React Website Builder
Dianne Pena
Exploring the Creative Power of CSS Filters and Blending
Exploring the Creative Power of CSS Filters and Blending
Joan Ayebola
How to Use WebSockets in Node.js to Create Real-time Apps
How to Use WebSockets in Node.js to Create Real-time Apps
Craig Buckler
Best Node.js Framework Choices for Modern App Development
Best Node.js Framework Choices for Modern App Development
Dianne Pena
SaaS Boilerplates: What They Are, And 10 of the Best
SaaS Boilerplates: What They Are, And 10 of the Best
Zain Zaidi
Understanding Cookies and Sessions in React
Understanding Cookies and Sessions in React
Blessing Ene Anyebe
Enhanced Internationalization (i18n) in Next.js 14
Enhanced Internationalization (i18n) in Next.js 14
Emmanuel Onyeyaforo
Essential React Native Performance Tips and Tricks
Essential React Native Performance Tips and Tricks
Shaik Mukthahar
How to Use Server-sent Events in Node.js
How to Use Server-sent Events in Node.js
Craig Buckler
Five Simple Ways to Boost a WooCommerce Site’s Performance
Five Simple Ways to Boost a WooCommerce Site’s Performance
Palash Ghosh
Elevate Your Online Store with Top WooCommerce Plugins
Elevate Your Online Store with Top WooCommerce Plugins
Dianne Pena
Unleash Your Website’s Potential: Top 5 SEO Tools of 2024
Unleash Your Website’s Potential: Top 5 SEO Tools of 2024
Dianne Pena
How to Build a Chat Interface using Gradio & Vultr Cloud GPU
How to Build a Chat Interface using Gradio & Vultr Cloud GPU
Vultr
Enhance Your React Apps with ShadCn Utilities and Components
Enhance Your React Apps with ShadCn Utilities and Components
David Jaja
10 Best Create React App Alternatives for Different Use Cases
10 Best Create React App Alternatives for Different Use Cases
Zain Zaidi
Control Lazy Load, Infinite Scroll and Animations in React
Control Lazy Load, Infinite Scroll and Animations in React
Blessing Ene Anyebe
Building a Research Assistant Tool with AI and JavaScript
Building a Research Assistant Tool with AI and JavaScript
Mahmud Adeleye
Understanding React useEffect
Understanding React useEffect
Dianne Pena
Web Design Trends to Watch in 2024
Web Design Trends to Watch in 2024
Juliet Ofoegbu
Building a 3D Card Flip Animation with CSS Houdini
Building a 3D Card Flip Animation with CSS Houdini
Fred Zugs
How to Use ChatGPT in an Unavailable Country
How to Use ChatGPT in an Unavailable Country
Dianne Pena
An Introduction to Node.js Multithreading
An Introduction to Node.js Multithreading
Craig Buckler
How to Boost WordPress Security and Protect Your SEO Ranking
How to Boost WordPress Security and Protect Your SEO Ranking
Jaya Iyer
Understanding How ChatGPT Maintains Context
Understanding How ChatGPT Maintains Context
Dianne Pena
Building Interactive Data Visualizations with D3.js and React
Building Interactive Data Visualizations with D3.js and React
Oluwabusayo Jacobs
JavaScript vs Python: Which One Should You Learn First?
JavaScript vs Python: Which One Should You Learn First?
Olivia GibsonDarren Jones
13 Best Books, Courses and Communities for Learning React
13 Best Books, Courses and Communities for Learning React
Zain Zaidi
5 jQuery.each() Function Examples
5 jQuery.each() Function Examples
Florian RapplJames Hibbard
Implementing User Authentication in React Apps with Appwrite
Implementing User Authentication in React Apps with Appwrite
Yemi Ojedapo
AI-Powered Search Engine With Milvus Vector Database on Vultr
AI-Powered Search Engine With Milvus Vector Database on Vultr
Vultr
Understanding Signals in Django
Understanding Signals in Django
Kabaki Antony
Why React Icons May Be the Only Icon Library You Need
Why React Icons May Be the Only Icon Library You Need
Zain Zaidi
View Transitions in Astro
View Transitions in Astro
Tamas Piros
Getting Started with Content Collections in Astro
Getting Started with Content Collections in Astro
Tamas Piros
What Does the Java Virtual Machine Do All Day?
What Does the Java Virtual Machine Do All Day?
Peter Kessler
Become a Freelance Web Developer on Fiverr: Ultimate Guide
Become a Freelance Web Developer on Fiverr: Ultimate Guide
Mayank Singh
Layouts in Astro
Layouts in Astro
Tamas Piros
.NET 8: Blazor Render Modes Explained
.NET 8: Blazor Render Modes Explained
Peter De Tender
Mastering Node CSV
Mastering Node CSV
Dianne Pena
A Beginner’s Guide to SvelteKit
A Beginner’s Guide to SvelteKit
Erik KückelheimSimon Holthausen
Brighten Up Your Astro Site with KwesForms and Rive
Brighten Up Your Astro Site with KwesForms and Rive
Paul Scanlon
Which Programming Language Should I Learn First in 2024?
Which Programming Language Should I Learn First in 2024?
Joel Falconer
Managing PHP Versions with Laravel Herd
Managing PHP Versions with Laravel Herd
Dianne Pena
Accelerating the Cloud: The Final Steps
Accelerating the Cloud: The Final Steps
Dave Neary
An Alphebetized List of MIME Types
An Alphebetized List of MIME Types
Dianne Pena
The Best PHP Frameworks for 2024
The Best PHP Frameworks for 2024
Claudio Ribeiro
11 Best WordPress Themes for Developers & Designers in 2024
11 Best WordPress Themes for Developers & Designers in 2024
SitePoint Sponsors
Top 10 Best WordPress AI Plugins of 2024
Top 10 Best WordPress AI Plugins of 2024
Dianne Pena
20+ Tools for Node.js Development in 2024
20+ Tools for Node.js Development in 2024
Dianne Pena
The Best Figma Plugins to Enhance Your Design Workflow in 2024
The Best Figma Plugins to Enhance Your Design Workflow in 2024
Dianne Pena
Harnessing the Power of Zenserp for Advanced Search Engine Parsing
Harnessing the Power of Zenserp for Advanced Search Engine Parsing
Christopher Collins
Build Your Own AI Tools in Python Using the OpenAI API
Build Your Own AI Tools in Python Using the OpenAI API
Zain Zaidi
The Best React Chart Libraries for Data Visualization in 2024
The Best React Chart Libraries for Data Visualization in 2024
Dianne Pena
7 Free AI Logo Generators to Get Started
7 Free AI Logo Generators to Get Started
Zain Zaidi
Turn Your Vue App into an Offline-ready Progressive Web App
Turn Your Vue App into an Offline-ready Progressive Web App
Imran Alam
Clean Architecture: Theming with Tailwind and CSS Variables
Clean Architecture: Theming with Tailwind and CSS Variables
Emmanuel Onyeyaforo
How to Analyze Large Text Datasets with LangChain and Python
How to Analyze Large Text Datasets with LangChain and Python
Matt Nikonorov
6 Techniques for Conditional Rendering in React, with Examples
6 Techniques for Conditional Rendering in React, with Examples
Yemi Ojedapo
Introducing STRICH: Barcode Scanning for Web Apps
Introducing STRICH: Barcode Scanning for Web Apps
Alex Suzuki
Using Nodemon and Watch in Node.js for Live Restarts
Using Nodemon and Watch in Node.js for Live Restarts
Craig Buckler
Task Automation and Debugging with AI-Powered Tools
Task Automation and Debugging with AI-Powered Tools
Timi Omoyeni
Quick Tip: Understanding React Tooltip
Quick Tip: Understanding React Tooltip
Dianne Pena
12 Outstanding AI Tools that Enhance Efficiency & Productivity
12 Outstanding AI Tools that Enhance Efficiency & Productivity
Ilija Sekulov
React Performance Optimization
React Performance Optimization
Blessing Ene Anyebe
Introducing Chatbots and Large Language Models (LLMs)
Introducing Chatbots and Large Language Models (LLMs)
Timi Omoyeni
Migrate to Ampere on OCI with Heterogeneous Kubernetes Clusters
Migrate to Ampere on OCI with Heterogeneous Kubernetes Clusters
Ampere Computing
Get the freshest news and resources for developers, designers and digital creators in your inbox each week