PHP
This article is a stub. You can help the IndieWeb wiki by expanding it.
PHP is an open source programming language and web server runtime environment used for many IndieWeb projects.
Projects
Libraries
- php-mf2 - Microformats 2 parser
- mention-client-php - Client library for sending webmention notifications
- indieauth-client-php - Sample implementation and helper methods for an IndieAuth client.
- php-comments - Helper for parsing and presenting comments from external sites
- representative-h-card-php - Find the representative h-card for a given page
- more libraries on the indieweb Github
- mf-cleaner for handling microformats2 array structures better
Articles
Articles about the use of PHP, especially for software that you are expected to download and install on your own domain:
Silos
Silos using PHP:
- Tumblr
Troubleshooting
UTF8
While there are a number of symptoms (weird looking characters, one character split into two), the problems with UTF8 handling in PHP happen for a handful of different reasons. Here are some suggested fixes for some cases.
- check the HTTP header returned, it should have:
if it does not then you may need a line like this in your PHP code before it outputs any HTML:Content-Type: text/html; charset=UTF-8
- header('Content-type: text/html; charset=UTF-8');
session start failed
If you get an error like:
Warning: session_start() [function.session-start]: open(/home/.../tmp/sess_..., O_RDWR) failed: No such file or directory
- Look like the server can't write to /home/.../tmp/
- so either it used to be able to, or it used to write to some other path
- ssh in, and see what the permissions for /home/tantek/tmp
- Or it's possible the session.save_path configuration changed. http://us2.php.net/manual/en/function.session-save-path.php
Possible resolutions:
- If your webhosting is a shared server
- start a ticket with your hosting provider, OR
- add this code to your PHP application somewhere before session access:
if (!is_dir(ini_get('session.save_path'))) {
mkdir(ini_get('session.save_path'), 0700, true);
}- This code auto-creates the PHP session storage directory if it doesn't already exist (inspired by the
mkdir
suggestion at [1], but tightened up with a conditional and tighter perms) - You may (should) consider providing additional error handling if the
mkdir
fails, and at some point provide the user an error message describing the error in enough detail that they can either file a support ticket with their webhosting provider, or ask a specific question in an appropriate community.
- This code auto-creates the PHP session storage directory if it doesn't already exist (inspired by the
- 2014-08-07 Tantek Γelik: These steps worked for me this past week using Falcon on shared webhosting. If Please only edit these instructions if you are documenting how you actually solved a problem firsthand, not how it might or should be possible.
- OR write a completely different non-filesystem method of session handling.
- See: http://websec.io/2012/08/24/Shared-Hosting-PHP-Session-Security.html for specific suggestions.
- If this is on your local dev setup (e.g. yourdomain.dev on your laptop)
- check your local dev php.ini to make sure it is setting session.save_path, if not fix it.
- don't know where is your local dev php.ini?
- create a file like phpinfo.php on your local dev setup with:
<!doctype html><meta charset=utf-8><title>php info</title><?php phpinfo();?>
- go access that phpinfo.php e.g. if you put it in a test directory: yourdomain.dev/test/phpinfo.php
- look for "Loaded Configuration File:" and it will tell you where is your local dev php.ini,
- create a file like phpinfo.php on your local dev setup with:
- don't have a local dev php.ini? if you see: "Loaded Configuration File: (none)" then you need to make one
- look for "Configuration File (php.ini) path" in that same output from above.
- go to that directory and look for a php.ini.default file
- copy it to php.ini e.g. with
cp php.ini.default php.ini
- if you get an error like
then you need to use sudo:cp: /etc/php.ini: Permission denied
sudo cp php.ini.default php.ini
- restart your local dev setup Apache, e.g. in a terminal window on your local dev machine:
sudo apachectl -k graceful</blockquot>
- if you see an error/warning like:
ignore it. Your local dev setup should work now.httpd: Could not reliably determine the server's fully qualified domain name
- if you instead (or also) saw an error like:
then you forgot to use sudo. Try again with the exact sudo apachectl -k graceful command above.httpd not running, trying to start
(13)Permission denied: make_sock: could not bind to address [::]:80
(13)Permission denied: make_sock: could not bind to address 0.0.0.0:80
no listening sockets available, shutting down
Unable to open logs
- don't know where is your local dev php.ini?
- 2014-08-07 Tantek Γelik: These steps worked for me this past week using a Macbook Air running OSX 10.7 and default Apache/PHP. Please only edit these instructions if you are documenting how you actually solved a problem firsthand, not how it might or should be possible.
- check your local dev php.ini to make sure it is setting session.save_path, if not fix it.
- Hopefully that fixes the "Warning: session_start()" error. If not, please ask in IRC and document further description/details below this item.
Criticism
Fatal error memory exhausted
Can run out of memory on servers sometimes, and give a message like:
- e.g. on http://yottabytes.info/?p=10497 (on 2014-06-08 15:28 EDT):
Fatal error: Allowed memory size of 41943040 bytes exhausted (tried to allocate 32 bytes) in /home/johnkrol/public_html/wp-includes/post.php on line 1961
- Examples on: WordPress [2], Drupal [3], and Joomla [4]
Recommendations
To fully avoid this problem one needs to figure out what the maximum amount of memory ones PHP process can need, check what amount of memory that is available on ones server, subtract any non-PHP processes from that amount of memory and then divide the remaining memory with the maximum amount of memory ones PHP process can need. The resulting number is the maximum amount of PHP processes one should run at once and ones server should be configured to never accept more than that or else be at the hands of the even worse fate than the mentioned white screen of death: The eternal doom of swapping that results when processes starts to use swap memory and processes therefore take much much longer to run and as a result more and more requests piles up so that the server sometimes can't recover itself at all but needs to be shut down.
Strict memory limits and limits on amount of parallel PHP processes are meant to avoid such swapping issues, but shared hosting often put very restrictive memory limits making it hard for larger and more demanding PHP applications like Drupal and WordPress to fit inside of that. The alternative is often to look at either managing a VPS oneself and configure that to fit ones application as just described or to get a managed offering from a hosting provider or a PaaS and ensure that it gets configured correctly.
An added complication when it comes to the LAMP stack is that sometimes the MySQL server is run on the same server as the PHP is and then compete for the same memory, which makes it even harder to figure out how much memory each process can be allowed to consume with the result of much stricter memory limits to be on the safe side.
See Also
- language
- CASSIS
- The WordPress statistics give some overview of popularity among PHP versions
- Pear
- http://php.net/manual/en/history.php.php
- https://twitter.com/jensimmons/status/1096097437469601797
- "Letβs hear it from the fans of the PHP include!
<?php include("foobar.php"); ?>
ππ€ͺπ€πΉπ―
(Any of us left?)" @jensimmons February 14, 2019
- "Letβs hear it from the fans of the PHP include!
- https://twitter.com/seldo/status/1205152990044180482
- "The last 10 years of web development have just been a long, slow walk back to the fantastic developer ergonomics and resilience of a PHP web app." @seldo December 12, 2019
- https://twitter.com/scottjehl/status/1304540564067622913
- "modern web dev is an extreme overreaction to not liking some php" @scottjehl September 11, 2020
- https://twitter.com/VicVijayakumar/status/1587462991955591168
- "1995: PHP is dead, learn ColdFusion
2002: PHP is dead, learn ASPβ.net
2003: PHP is dead, learn Django
2004: PHP is dead, learn Ruby on Rails
2010: PHP is dead, learn Flask
2011: PHP is dead, learn AngularJS
2016: PHP is dead, learn Next.js
2022: okay this is awkward" @VicVijayakumar November 1, 2022
- "1995: PHP is dead, learn ColdFusion