DEV Community

Tom
Tom

Posted on • Updated on

Why PHP? Thoughts…

@robertobutti
https://dev.to/robertobutti/why-php-2e4h

Read this article; here are some thoughts on the subject.
PHP will never ever be on par with python because these three reasons:

  1. No native SET data structure support, which is a direct proof that php never was designed for data programming. Amazing @krakjoe and friends introduced it only in 2016 in Ds pecl extension, while python have had it from start.
    Consider algorithmic problems such as leetcode stuff, php developer would struggle in half of them not thinking data first - with set structure being a solution in half of this half. Famous expression - framework is not the way you code, it is the way you think. Same situation here. Programming language is not the way you code - but how you think as a programmer, what is your approach, etc.

  2. No native coroutine/async/await support in php. Same situation, only adopting ReactPHP/Swoole would give you this instrument, although you’ll have to struggle implementing async solutions for common jobs like databases, etc. And core php team never thought of that in the first place, why?
    To create python’s FastAPI stuff you’ll have first to invent it with only Swoole being native implementation of the approach, still it is an external library.

  3. Multithreading? Forget it. No native support as well. First thing I had to do as a math student 30 years ago was to implement rectangles method multithreadingly. Guess what, you can’t do it in php.


Funny story is that I never hesitated which language to choose, PHP was there for me right away :)
And I am not trying to start a hate topic. I only think that one should be realistic and aware about cans and cannots with this or that instrument.

K! THX! BYE!

Top comments (5)

Collapse
 
kwnaidoo profile image
Kevin Naidoo • Edited

Thank you for opening up this discussion. I am a big fan of PHP so hope you don't mind me giving you a perspective from a PHP developer's point of view.

I have experience in both Python and PHP, both are great languages. To be fair, you can't compare PHP with Python for data science. PHP is a web development language and not a general-purpose language.

  1. You are speaking of Pandas and Numpy when you say "data" (I think). These are for machine learning which PHP is not designed for and never claimed to be. Its main purpose is web development. PHP was initially designed to be a template layer on top of C. Therefore, its functions are essentially wrappers around C functions, and it can efficiently handle large datasets - big CSV/XML files. I have built large parsers in PHP that can parse gigabytes of XML/JSON data without any major problems.

  2. We use queues - queues are robust. You can retry and peak into the data as it's being queued, you can also distribute jobs across multiple machines. If a worker dies - another worker can just pick up the job. Async-Await by default is handled inside your application's life cycle on the machine it was spawned. If the worker dies - your job dies. Sure there are ways around this but by default, this is the behavior. In large Python apps - the approach is also to use queues via celery.

  3. PHP, while not exactly the same as multi-threading can do something similar. With "pcntl_fork" - you can spawn multiple processes that run in parallel. Usually, queues are better for this type of task.

Collapse
 
jesusantguerrero profile image
Jesus Guerrero

A programming languages is just a tool to solve problems just like 20% or less of the cases would need something PHP or its ecosystem doesn't have.

And there's the answer PHP delivers, users care about results PHP is a fast and convenient way of doing web programming

Collapse
 
mcharytoniuk profile image
Mateusz Charytoniuk

PHP framework that handles multithreading, coroutines, uses data structures: resonance.distantmagic.com/

What is the issue with plugins?

Collapse
 
tkx profile image
Tom

Thank you for this gem that your framework is. Any non-chinese person who figured out how swoole works deserves a salary raise :) because lack of docs etc…
And there are of course no problem with extensions, but you have to be aware of their existence, at least. While the very presence of a language keyword ‘await’ is telling you that a language has this mechanism.
I think php docs should put the most important extensions at the beginning.

Collapse
 
mcharytoniuk profile image
Mateusz Charytoniuk

Thank you so much, I really appreciate it :)