PHP script to check MySQL replication status

If you have MySQL replication running in either a master-slave or master-master type setup then don’t assume everything is running perfectly all the time. Power cuts and other disasters do happen so you need to check periodically to ensure it’s all working. This post has a PHP script to check for any MySQL replication errors and then emails if there are any issues

PHP’s unserialize function and E_NOTICE

PHP has the serialize and unserialize functions for converting data into a storable value (for example being able to store an array in a database field). An issue with the unserialize function is that it will issue an E_NOTICE error if the data is notunserializeable. This post looks at how to prevent the notices from being displayed if you have error reporting at a level that will show notices.

Categories PHP

PHP email validation with filter_var

There’s no longer any need in PHP to create your own regular expressions to try to validate an email address; simply use filter_var() instead. This is available from PHP 5.2.0.

Categories PHP

Sending a username and password with PHP file_get_contents()

Last week I looked at how send a username and password with PHP CURL. Using CURL is useful because you can examine the return information to see if the request was successful etc, but if your hosting provider doesn’t have CURL for PHP enabled then you can still attempt to get the file by using file_get_contents and passing the authentication as part of the $context parameter.

Categories PHP

Sending a username and password with PHP CURL

CURL and PHP combined can be really useful for getting data from websites, connecting to APIs (such as the Google Analytics API) and so on. Sometimes you may need to connect to a website that is password protected so this post looks at how to pass the username and password with PHP and CURL.

Categories PHP

Reading through a directory with PHP

PHP’s opendir() readdir() and closedir() are used for reading the contents of a directory (there’s also glob() and scandir() but I’ll cover those in later posts). Combined with functions like is_file() is_dir() and is_link() and you can easily build up a directory tree or process files etc.

Categories PHP