Live data from Hacker News

An Internet of PHP

timotijhof.net

111–120 of 333 posts

Re: An Internet of PHP

#111

From W3Tech; > PHP is used by 77% of all the websites whose server-side programming language we know. I had a quick look at the methodology section, but it’s not clear to me how accurate this data is. Determining whether a site uses PHP can be relatively straightforward (especially with default extensions / if Wordpress is used / etc), but if a site (potentially using a different language) is behind a reverse proxy/u…

A lot of news outlets, e-learning and e-commerce websites are running on CMS/Frameworks made with PHP. Just to mention a few of them:

- WordPress - Joomla! - Magento - Moodle - Zend Framework/Cart - Laravel - Symfony - Open E-commerce

If you count all the websites using one of the above items, you will come up with a huge list of websites.

And way too many Academic sites are running on PHP.

The LAMP oder LNMP Combo (nginx instead of Apache httpd) is strong.

Re: An Internet of PHP

#112

From W3Tech; > PHP is used by 77% of all the websites whose server-side programming language we know. I had a quick look at the methodology section, but it’s not clear to me how accurate this data is. Determining whether a site uses PHP can be relatively straightforward (especially with default extensions / if Wordpress is used / etc), but if a site (potentially using a different language) is behind a reverse proxy/u…

I agree. I always doubted these figures (I'm a PHP dev myself, so I wouldn't mind these figures being true). I think the methodology is shady. I wonder if they use what the server indicates. I think some servers like Apache with php mod send this information to the client in a header. But most servers don't. Therefore they maybe use this as "from all the servers giving a backend language information, PHP represents 77%" which wouldn't be surprising. The question is how many websites in your data don't give any information about the language used under the hood?

I think we should stop using these numbers. GitHub uses ruby on rails but we know it from the developer team, not from what the server tells us. How many websites communicate about their backend infrastructure?

I don't doubt Wordpress powers many websites out there. But I'm tired of these figures which don't mean anything to me. Especially that if you look for all job ads, PHP isn't so big (except in some PHP-centric countries like France).

You can't just make up numbers. If you give me statistics, give me the methodology you used and all the details. Otherwise I suggest we all start saying Haskell powers 87% of the web. After all, if you can invent what suits you, I can do the same.

Re: An Internet of PHP

#113
post #7

I've always liked PHP. You wouldn't pick it for your job interview's coding test if you had a choice (Python all the way there), but it's so intertwined with the internet and what we've learned about programming over the years. First mover advantage kind of deal. And I've never had to deal with ESM/CJS/AMD whatever module nonsense with PHP. No transpiling anything, just edit and refresh. And so many useful functions…

Bad rap comes from the inconsistency of the early APIs. The ability to interleave code and HTML was also tacky and never taken seriously but I think touted highly by some as a killer feature. The language is very unplanned, go look at an equality chart for PHP, it makes JavaScript blush as well.

The bad original library, the original lack of features that help against bad coding practices and the fact that it is so accessible to beginner programmers that you’ll find a lot of beginner code.

The ability to mix html and code means it’s extremely easy to get started which is the big strength.

Re: An Internet of PHP

#114
One thing I absolutely love about PHP is the mod_intl which is almost always enabled everywhere. It provides ICU Transliterator and BreakIterator which is godsand to handle user-create content that's in Asian, Complex Script, etc.

Last I check a few year ago Java is the only other platform with as good ICU integration, and nodejs has BreakIterator but not Transliterator. Other platform require complex setup to install ICU as a third party library.

Re: An Internet of PHP

#115

Earlier quoted context omitted.

"The ability to interleave code and HTML was also tacky and never taken seriously" - That was the whole point of it! The day I found PHP and could leave behind the cgi-bin and SSI it became my favourite thing - and has paid me well for the last 20+ years :)

Putting HTML inside of scripted code blocks was legendary back in the day and every web-oriented language did it. I guess people have already forgotten about ASP and ColdFusion. Being able to for each an array into table rows? Game changing.

I have been coding in coldfusion (openbluedragon) on 2012. Still lurks in my dreams. I refactored to components (objects) some functionalities as a POC, it did not fit well with the main programmer.

Re: An Internet of PHP

#116

I like PHP, one issue which I face with PHP though is, that it is difficult to create a self-contained docker image. With node.js or java spring boot i can build an application with an http endpoint and create a single docker image with all included easily. With php I need 2 distinct containers, e.g., nginx, php-fpm and the code mounted on a volume to the the containers. So it seems to be more difficult for setup and…

What I went with was having both a web server (Apache/Nginx) and PHP-FPM in the same container image, held together by Supervisor: http://supervisord.org/

In my case, the Dockerfile looks a bit like the following:

  # Whatever base web server image you want, Debian/Ubuntu based here
  FROM .../nginx
  # Bloated packages for installing dependencies and also Supervisor
  RUN apt-get update \
      && apt-get -yq --no-upgrade install \
          software-properties-common \
          supervisor \
      && apt-get clean \
      && rm -rf /var/lib/apt/lists /var/cache/apt/*
  # Add repository for PHP 8
  RUN export LC_ALL="C.UTF-8" && add-apt-repository ppa:ondrej/php
  # Then we install PHP and the Nginx integration package (we use PHP-FPM)
  RUN apt-get update \
      && apt-get -yq --no-upgrade install \
          php8.2 php8.2-common php8.2-cli php8.2-dev php8.2-opcache ... php8.2-fpm \
      && apt-get clean \
      && rm -rf /var/lib/apt/lists /var/cache/apt/*
  # We will also need Composer for managing dependencies
  RUN curl -sS https://getcomposer.org/installer -o /tmp/composer-setup.php \
      && php /tmp/composer-setup.php --install-dir=/usr/local/bin --filename=Composer
  # Create directories, clear regular web server index directories
  RUN mkdir -p /run/php \
      && rm -rf /var/www/html && mkdir -p /var/www/html
  # Copy over config (whatever you have)
  COPY ./php_nginx/etc/nginx/nginx.conf /etc/nginx/nginx.conf
  COPY ./php_nginx/var/www/html /var/www/html
  COPY ./php_nginx/etc/supervisord.conf /etc/supervisord.conf
  # Copy PHP config (whatever you have)
  COPY ./php_nginx/etc/php/8.2/fpm/php.ini /etc/php/8.2/fpm/php.ini
  COPY ./php_nginx/etc/php/8.2/fpm/php-fpm.conf /etc/php/8.2/fpm/php-fpm.conf
  COPY ./php_nginx/etc/php/8.2/fpm/pool.d/www.conf /etc/php/8.2/fpm/pool.d/www.conf
  # Default run script
  COPY ./php_nginx/docker-entrypoint.sh /docker-entrypoint.sh
  RUN chmod +x /docker-entrypoint.sh
  CMD "/docker-entrypoint.sh"
Here's the entrypoint:

  #!/bin/sh
  echo "Software versions..."
  nginx -V && supervisord --version

  echo "Running Supervisor..."
  supervisord --configuration=/etc/supervisord.conf
Here's a snippet of nginx.conf, how to get *.php to be executed (put inside of a server block):

  location ~ \.php$ {
      include snippets/fastcgi-php.conf;
      fastcgi_pass 127.0.0.1:9000;
  }
And here's the Supervisor configuration:

  [supervisord]
  nodaemon=true
  
  [program:php-fpm]
    command=/usr/sbin/php-fpm8.2 -c /etc/php/8.2/fpm/php-fpm.conf --nodaemonize
    stdout_logfile=/dev/stdout
    stdout_logfile_maxbytes=0
    stderr_logfile=/dev/stderr
    stderr_logfile_maxbytes=0
  
  [program:nginx]
    command=/usr/sbin/nginx
    stdout_logfile=/dev/stdout
    stdout_logfile_maxbytes=0
    stderr_logfile=/dev/stderr
    stderr_logfile_maxbytes=0
Of course, it isn't necessarily the most idiomatic way to work with containers, but if you have health checks then it should still be fine. With a base image a little like this, you should then be able to build your own images with the code included, or use a bind mount. You can probably get images that work a bit like this pre-made, this is just how I do things, in case you're curious about what that might look like from scratch. Apache also has mod_php which would be even simpler, though generally will perform worse than PHP-FPM.

Curiously, this is also one of the few detriments of PHP in my eyes - when compared to something like Java that just spits out one .jar that can be run on anything with a compatible JDK version (at least with how things are done in the recent years vs standalone Apache Tomcat).

Re: An Internet of PHP

#117
This is great, and I'm glad for the PHP developers out there. But if I go job hunting, it's not PHP skills that offer the highest earning potential. At least not that I've encountered.

How much revenue generation occurs on PHP? I'll cede the argument about the e-commerce platforms and CRMs, but I'm just not convinced that PHP is where a budding developer should be focusing their efforts. You enter the business/corporate world and there are tons of applications out there running the world, not just websites. Those applications are predominantly written in languages like .NET, Java, JS/ECMAScript, Python, Rust, and Go. Also, among the managed languages like .NET/Java/JS the knowledge is quite transferrable and sometimes almost identically named.

I'm not trying to bash PHP as a language, but every time I see this argument it's the same. Evangelizing PHP also seems to come with a requirement to mention Wordpress, Wikipedia, and Facebook. I'm sure there's money to be made in PHP, and I'm sure it's a great language for the internet. But learning .NET or Java is likely to have a much larger window of opportunity. Also, if you have a specific industry you want to work in you should be looking at the language predominately sought after in that industry.

I think this is why a lot of developers bash PHP, it's not that it's a non-valid choice. It's that it has limited applicability. I would never advise someone to learn PHP as their first language.

Re: An Internet of PHP

#118

I like PHP, one issue which I face with PHP though is, that it is difficult to create a self-contained docker image. With node.js or java spring boot i can build an application with an http endpoint and create a single docker image with all included easily. With php I need 2 distinct containers, e.g., nginx, php-fpm and the code mounted on a volume to the the containers. So it seems to be more difficult for setup and…

Don't follow any advice to use Apache as a reverse proxy, or bundle php with a classic web server.

There are real application servers using an event loop by now, most notably Roadrunner (https://roadrunner.dev), FrankenPHP (https://frankenphp.dev), Laravel Octane (https://laravel.com/docs/10.x/octane#introduction), Swoole Bridge for Symfony (https://github.com/insidestyles/swoole-bridge-bundle).

In general, you can do a lot with OpenSwoole or Roadrunner. They are vastly superior (in a container scenario) to any other suggestion in this thread!

Re: An Internet of PHP

#119
As an ex-PHP developer (almost 10 years now), I do not miss it. As a language, it is a scripting language with an okay interpreter. But as an eco-system, it is a hot mess. It has both the worst software developers (and I was one of them) as well as the worst clients (and the cheapest, regardless of geography).

It is not a surprise that PHP is running the web. That's because WordPress made sites/e-commerce accessible to the average Joe. Despite the massive security issues with these setups, it has enabled a large number of people to run businesses.

But if you are a software developer, I'd strongly advice you not to do PHP.

Re: An Internet of PHP

#120
post #119

As an ex-PHP developer (almost 10 years now), I do not miss it. As a language, it is a scripting language with an okay interpreter. But as an eco-system, it is a hot mess. It has both the worst software developers (and I was one of them) as well as the worst clients (and the cheapest, regardless of geography). It is not a surprise that PHP is running the web. That's because WordPress made sites/e-commerce accessible…

Modern PHP may as well be a new language. But then node came along. It's almost like PHP users couldn't stand a clean ecosystem.
Post reply on HN