Thursday 24 September 2015

10 Things You Need to Know about PHP 7

With that out of the way, let’s check out PHP 7.

1. The Name’s PHP 7 (Not 6)


The current stable release uses the version number PHP 5.6. After some disputethe development team decided they would omit the PHP 6 name for the next major release. PHP 6 already existed in the past as an experimental project but never reached the production phase.
To prevent users from mixing up the former attempt with the latest development, the new major release will run under the name of PHP 7.

IMAGE: Software Development Times

2. The Brand Spanking New Zend Engine

The Zend engine has been powering PHP since 1999 when it was introduced with the then new PHP 4 release. Zend – not to confused with the Zend Framework – is an open-source execution engine written in C that interprets the PHP language. The current PHP 5.X series use Zend Engine II that enhanced the funtionality of the initial engine and adds an extensible object model and a significant performance enhancement to the language.
PHP 7 receives a brand new version of the engine coming under the code name of PHP#NG (Next Generation).

IMAGE: A Talk on ZendCon-2014

3. Twice The Speed

The most easily recognizable advantage of the new PHPNG engine is the significant performance improvement. The development team of PHPNG refactored the Zend Engine, remarkably optimized memory usage and addedjust-in-time compilation (JIT) which allows compilation at run time rather than prior to execution.
The results? You can see the performance benchmarks provided by the Zend Performance Team below. By using PHP 7 not only your code will be executed faster but you will also need fewer servers to serve the same amount of users.



IMAGE: Zend.com

4. Facilitates Error Handling

To say the least, handling fatal and catchable fatal errors have never been an easy task for PHP coders. The new Engine Exceptions will allow you to replace these kind of errors with exceptions. If the exception is not caught, PHP will continue to return the same fatal errors as it does in the current 5.X series.
The new \EngineException objects don’t extend the \Exception Base Class. This ensures backward compatibility and results in two different kinds of exceptions in error handling: traditional and engine exceptions.
To enable programmers to catch both, PHP 7 introduces a new shared Parent Class under the name of \BaseException.

IMAGE: Wiki.PHP.net

5. 64-Bit Windows Systems Support

PHP is a prominent member of the LAMP stack which means its native environment is Linux – but it’s also possible to run it on a Windows system. The 5.X series don’t yet provide 64-bit integer or large file support, so until now x64 builds have been considered experimental.
PHP 7 will change this as it introduces consistent 64-bit support which means both native 64-bit integers and large files will be supported, allowing you to confidently run the language on your 64-bit Windows system in the future.

6. New Spaceship and Null Coalescing Operators

The Spaceship operator runs under the official name of Combined Comparison Operator. The notation of the new operator looks like this: <=> (kind of like a simplified spaceship, if you imagine it right).
The spacehip operator returns 0 if both operands are equal, 1 if the left is greater, and -1 if the right is greater. It’s also called a three-way comparison operator, and it already exists in other popular programming languages like Perl and Ruby.

IMAGE: Wiki.PHP.net
The Null Coalescing operator is denoted with two question marks ( ?? ). You can use it when you want to check if something exists and return a default value, in case it doesn’t. The coalesce operator returns the result of its first operand if it exists and is not null, and the second operand in any other cases.
Here’s how the new operator reduces the time spent with basic declarations:

IMAGE: Wiki.PHP.net

7. Enables Accurate Type Declarations

Have you ever wanted to prevent unintended return values by declaring the return type of a function? Well, the new PHP 7 enables developers to enhance the quality of their code with the help of return type declarations.
The image below depicts a very simple use case where the foo() function is supposed to return an array. Check out more complicated examples here.

IMAGE: Wiki.PHP.net
To enhance the feature even more, PHP 7 introduces 4 new type declarations for scalar types: int, float, string and bool. The new scalar types allow developers to denote that they are expecting integers, floats, strings, or booleans to be returned. The new scalar types introduced by PHP 7 will also be supported by argument Type Hints that enables developers to force the type of parameters since the PHP 5.X series.

8. Adds Anonymous Classes

PHP 7 enables you to use anonymous classes, already a well-established practice in other object-oriented languages like C# and Java. An anonymous class is a class without a name. The object it instantiates has the same functionality as an object of a named class.
The syntax is the same as what we are used to in traditional PHP classes, only the name is missing. If anonymous classes are used well, they can speed up coding as well execution time. Anonymous classes are excellent when a class is used only once during execution and in cases when a class doesn’t need to be documented.

IMAGE: Wiki.PHP.net

9. Facilitates Imports From the Same Namespace

The new Group Use Declarations feature will be godsent to those of you who want to import many classes from the same namespace. The new syntax cuts verbosity, makes your code tidier and easier on the eyes, and saves you a lot of typing time.
It will also be easier to read through and debug codes, as group use declarations help you identify the imports that belong to the same module.

IMAGE: Wiki.PHP.net

10. Cleans Up The Room

The goal of PHP 7 was to free up the space to enable improvement, so it was necessary to get rid of many deprecated functionalities and old and unsupported Server APIs and extensions. If you want to check which are these in detail, clickhere and here.
All the removed items have been deprecated for a while in PHP 5 so most likely you haven’t used them for a long time. However please note if you have a legacy app running on older PHP versions the new PHP 7 can potentially break the code.


Source: http://www.hongkiat.com/blog/php7/

Sunday 30 August 2015

Some php crawler


1. The DomCrawler Component

The Crawler class provides methods to query and manipulate HTML and XML documents.

An instance of the Crawler represents a set (SplObjectStorage) of DOMElement objects, which are basically nodes that you can traverse easily.
More detail

2. PHPCrawl webcrawler library/framework


PHPCrawl is a framework for crawling/spidering websites written in the programming language PHP, so just call it a webcrawler-library or crawler-engine for PHP

PHPCrawl "spiders" websites and passes information about all found documents (pages, links, files ans so on) for futher processing to users of the library.

It is high configurable and provides several options to specify the behaviour of the crawler like URL- and Content-Type-filters, cookie-handling, robots.txt-handling, limiting options, multiprocessing and much more.

3. PHP Simple HTML DOM Parser

A HTML DOM parser written in PHP5+ let you manipulate HTML in a very easy way!
Require PHP 5+.
Supports invalid HTML.
Find tags on an HTML page with selectors just like jQuery.
Extract contents from HTML in a single line.

Wednesday 10 December 2014

How to Mount S3 Bucket on CentOS/RHEL and Ubuntu using S3FS

S3FS is FUSE (File System in User Space) based solution to mount an Amazon S3 buckets, We can use system commands with this drive just like as another Hard Disk in system. On s3fs mounted files systems we can simply use cp, mv and ls the basic Unix commands similar to run on locally attached disks.
If you like to access S3 buckets without mounting on system, use s3cmd command line utility to manage s3 buckets. s3cmd is also provides faster speed for data upload and download rather than s3fs. To work with s3cmd use next articles to install s3cmd in Linux systems and Windows systems.
amazon-banner
This article will help you to install S3FS and Fuse by compiling from source, and also help you to mount S3 bucket on your CentOS/RHEL and Ubuntu systems.

Step 1: Remove Existing Packages

First check if you have any existing s3fs or fuse package installed on your system. If installed it already remove it to avoid any file conflicts.
CentOS/RHEL Users:
 # yum remove fuse fuse-s3fs

Ubuntu Users:
 $ sudo apt-get remove fuse

Step 2: Install Required Packages

After removing above packages. First we will install all dependencies for fuse and s3cmd. Install the required packages to system use following command.
CentOS/RHEL Users:
 # yum install gcc libstdc++-devel gcc-c++ curl-devel libxml2-devel openssl-devel mailcap

Ubuntu Users:
 $ sudo apt-get install build-essential libcurl4-openssl-dev libxml2-dev mime-support

Step 3: Download and Compile Latest Fuse

Download and compile latest version of fuse source code. For this article we are using fuse version 2.9.3. Following set of command will compile fuse and add fuse module in kernel.
# cd /usr/src/
# wget http://downloads.sourceforge.net/project/fuse/fuse-2.X/2.9.3/fuse-2.9.3.tar.gz
# tar xzf fuse-2.9.3.tar.gz
# cd fuse-2.9.3
# ./configure --prefix=/usr/local
# make && make install
# export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig
# ldconfig
# modprobe fuse

Step 4: Download and Compile Latest S3FS

Download and compile latest version of s3fs source code. For this article we are using s3fs version 1.74. After downloading extract the archive and compile source code in system.
# cd /usr/src/
# wget https://s3fs.googlecode.com/files/s3fs-1.74.tar.gz
# tar xzf s3fs-1.74.tar.gz
# cd s3fs-1.74
# ./configure --prefix=/usr/local
# make && make install

Step 5: Setup Access Key

Also In order to configure s3fs we would required Access Key and Secret Key of your S3 Amazonaccount. Get these security keys from Here.
# echo AWS_ACCESS_KEY_ID:AWS_SECRET_ACCESS_KEY > ~/.passwd-s3fs
# chmod 600 ~/.passwd-s3fs
Note: Change AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY with your actual key values.

Step 6: Mount S3 Bucket

Finally mount your s3 bucket using following set of commands. For this example, we are using s3 bucket name as mydbbackup and mount point as /s3mnt.
# mkdir /tmp/cache
# mkdir /s3mnt
# chmod 777 /tmp/cache /s3mnt

# s3fs -o use_cache=/tmp/cache mydbbackup /s3mnt
# sudo s3fs insing-profile-test -o use_cache=/tmp/cache -o allow_other /folder_local

copied from techadmin