PHP 5.4 features and changes

  • The break and continue statements no longer accept variable arguments (e.g., break 1 + foo() * $bar;). Static arguments still work, such as break 2;.
  • Non-numeric string offsets – e.g. $a[‘foo’] where $a is a string – now return false on isset() and true on empty(), and produce a warning if you try to use them. Offsets of types double, bool and null produce a notice. Numeric strings (e.g. $a[‘2′]) still work as before. Note that offsets like ‘12.3’ and ‘5 foobar’ are considered non-numeric and produce a warning, but are converted to 12 and 5 respectively, for backward compatibility reasons.
  • Parameter names that shadow super globals now cause a fatal error. This prohibits code like function foo($_GET, $_POST) {}.
  • session_register, session_unregister is not available now.
  • Support for traits has been added.
  • Short array syntax has been added, e.g. $a = [1, 2, 3, 4]; or $a = [‘one’ => 1, ‘two’ => 2, ‘three’ => 3, ‘four’ => 4];.
  • Function array dereferencing has been added, e.g. foo()[0].
  • Closures now support $this.
  • <?= is now always available, regardless of the short_open_tag ini option.
  • Class member access on instantiation has been added, e.g. (new Foo)->bar().
  • Class::{expr}() syntax is now supported.
  • Binary number format has been added, e.g. 0b001001101.
  • Improved parse error messages and improved incompatible arguments warnings.
  • The session extension can now track the upload progress of files.
  • Built-in web server in CLI mode.
  • A new SAPI module named cli-server is now available.
  • mysqli_result() now implements Traversable. (It means you can loop through it using foreach)
  • The MySQL extensions mysql, mysqli and PDO_mysql use mysqlnd as the default library now. It is still possible to use libmysql by specifying a path to the configure options.
  • The default character set is now UTF-8, instead of ISO-8859-1, when the default_charset configuration setting is not set (“”, which is the default). This applies to functions such as htmlentities() and htmlspecialchars(), or any code that relies on determine_charset(NULL) internally.
  • It’s now possible to enforce the class’ __construct arguments in an abstract constructor in the base class.
No Comments | Tags:

Highlight terms while tailing a log

Sometimes I want to keep tailing a log and look for a term – for example if you are an e-commerce platform then you may like to keep a running tail somewhere while keeping en eye on “checkout” page.

Following code snippet will highlight the term:

tail -f /var/log/apache2/access.log | perl -p -e 's/(checkout)/\033[46;1m$1\033[0m/g;'

You can highlight two such terms as well:

tail -f /var/log/apache2/access.log | perl -p -e 's/(checkout|another)/\033[46;1m$1\033[0m/g;'

Any perl regex should work for the highlighting, if your terminal supports it.

No Comments | Tags: , , , ,

Setup IP to city/country detection using geoIP in php

Following instructions are for apache on ubuntu.

# Install GeoIP module for php5
sudo apt-get install php5-geoip
# Restart Apache
sudo /etc/init.d/apache2 restart
# Now, the country wide data is automatically installed with geoIP module. 
# But, if we want to have it at city level - we need to download the data.
# Here we are downloading the free database. Steps for paid database will be same
wget -N
# Now, extract the file
gunzip GeoLiteCity.dat.gz
# Time to copy the file to proper location
sudo cp GeoLiteCity.dat /usr/share/GeoIP/GeoIPCity.dat

Please note that we changed the name of the file. In case of paid version, changing the name won’t be required.


No Comments | Tags: , , , , , ,

My Experiments with AWS – 3 : lamp server, Elastic IP, DNS for ec2

Now that we can connect to the ec2 instance – we want to setup a basic website. I use ubuntu AMI – so, following instructions are for ubuntu. Similar instructions for other platforms can be ported as well.

Installing LAMP Server

# install Apache , PHP and MySql as a package
sudo tasksel install lamp-server
# we may want to enable some of the apache modules
# without rewrite = rewriting URLs will not work
sudo a2enmod rewrite
# headers and expires module will help in performance
sudo a2enmod headers
sudo a2enmod expires

read more »

1 Comment | Tags: , , , , , , ,

My Experiments with AWS – 2 : Connect to EC2 instance

In order to connect with an ec2 instance there are three prime prerequisites:

  • The key file (.pem extension) created while launching an EC2 instance in AWS.
  • Port 22 of the instance is open while launching the instance.
  • Know the public DNS of your EC2 instance.

read more »

1 Comment | Tags: , , , , , , , ,