PHP 6 Features
PHP 6′s Status
Several books have already been written and published about PHP 6, such as Professional PHP6 by Edward Lecky-Thompson & Steven Nowicki. Despite this, PHP6 does not exist yet. There is no PHP 6 beta or even alpha. PHP 6 does not exist.
To see that PHP 6 doesn’t exist yet, see PHP’s official Subversion page. Subversion, or svn, is the source code control software used for the development of PHP. There are instructions for getting the code for PHP 5.3 or 5.4, but not for any newer version:
PHP 5.3: svn checkout http://svn.php.net/repository/php/php-src/branches/PHP_5_3 php-src-5.3 PHP 5.4: svn checkout https://svn.php.net/repository/php/php-src/branches/PHP_5_4 php-src-5.4
As you can see here from the branches in the PHP source code the newest branch is PHP_5_3:
FIRST_UNICODE_IMPLEMENTATION/ 296285 16 months derick - Committing my session cookie patch; it's a bug fix and good to have in the h… ... PHP_4_4/ 295390 16 months derick - Set-up externals for the Zend engine so 4.4 can at least be build from SVN a… PHP_5_0/ 284180 2 years gwynne one more attempt at ridding us of some of those annoying mime types PHP_5_1/ 284180 2 years gwynne one more attempt at ridding us of some of those annoying mime types PHP_5_2/ 311125 2 months dmitry Fixed crash on recursive error handler invocation PHP_5_2_WITH_DRCP/ 284180 2 years gwynne one more attempt at ridding us of some of those annoying mime types PHP_5_3/ 313616 31 hours scottmac When we have a blocking SSL socket, respect the timeout option. reading from SS… PHP_5_4/ 313646 3 hours stas No E_STRICT in production
(Older code branches omitted for brevity.)
There’s no PHP 6 code branch yet. Notice the FIRST_UNICODE_IMPLEMENTATION branch – the story behind this code branch, and why it delayed PHP 6 follows.
What does exist is an official todo for PHP 6, authored by Andrei Zmievski, which includes a rough list of PHP 6 features in the PHP Wiki.
UPDATE 21 July 2011: Now the PHP 5.4 Alpha has been released, a PHP 6 branch may exist for PHP’s developers without showing up on PHP’s public subversion. The code for PHP 5.4 did not show up on the sites above until the PHP 5.4 Alpha was released.
Reasons for Delays to PHP 6
The reasons for the delay to PHP 6 appear to be:
- Issues with Unicode support: The development team initially decided to use UTF-16 internally in PHP 6. This causes double memory usage for strings, more CPU usage and increased complexity of coding PHP 6. Using UTF-16 apparently took a lot of fun out of developing PHP, caused tension amongst PHP’s developers and slowed development. The choice to use UTF-16 was aborted by Rasmus Lerdorf, creator of PHP, in 2010. The developers restarted the Unicode implementation.
- PHP 5.3 took some PHP 6 features: PHP 5.3 included many of the features slated as desirable for PHP 6. This removed a lot of momentum for PHP 6.
- High Hopes: PHP 6 is a major version number change. It’s possible in a major release to make significant changes, including making breaks from the past. Agreeing and delivering major changes can take some time.
- Feature Set Not Finalized: Agreement hasn’t been reached on the features in PHP 6.0.
- Lack of Urgency: PHP works very well. There are no burning issues forcing the release of PHP 6.
- PHP 5.4 takes some PHP 6 features: Rasmus Lerdorf previously stated, when he scrapped PHP 6′s original Unicode implementation, that there may be a PHP 5.4 yet, or PHP may go straight to version 6. Jani Taskinen created a PHP 5.4 development branch on 11 March 2010, but this appears to be due to frustration as being able to move PHP’s development forward. The PHP 5.4 code branch is no longer there. There is however an official PHP 5.4 todo wiki, with Stanislav Malyshev as the tentative release manager. So it looks there will be PHP 5.4, which would push out the PHP 6.0 release further. UPDATE on 24 July 2011: The PHP 5.4 Alpha has been released, and it includes some features originally targeted for PHP 6.0, such as traits and the removal of register_globals and safe_mode.
PHP 6 Features
The likely set of PHP6 features is:
- Internationalization: Native Unicode – UTF-8 – to the core (strings, APIs).
- Performance: Page level (opcode) caching through moving Alternative PHP Cache (APC) into the PHP core. Native application caching.
- Break to label: Sending a break to a label (like a goto).
- Enhanced array indexing: Array indexing can be used to substring or take an array slice.
- Removed features: Magic quotes will be removed.
The are quite a few more minor features and changes in PHP 6.
[smartwebdeveloper]
43 Tips for Optimizing PHP code
43 Tips for Optimizing PHP code
Here is the list of 43 short tips you can use for writing an optimized and more efficient PHP code:
- If a method can be static, declare it static. Speed improvement is by a factor of 4.
-
echo
is faster than
print.
- Use echo’s multiple parameters instead of string concatenation.
- Set the maxvalue for your for-loops before and not in the loop.
- Unset your variables to free memory, especially large arrays.
- Avoid magic like __get, __set, __autoload
-
require_once()
is expensive
- Use full paths in includes and requires, less time spent on resolving the OS paths.
- If you need to find out the time when the script started executing,
INSERT:CONTENT:END SERVER['REQUEST_TIME']is preferred to
time() - See if you can use strncasecmp, strpbrk and stripos instead of regex
-
str_replace
is faster than
preg_replace, but
strtris faster than
str_replaceby a factor of 4
- If the function, such as string replacement function, accepts both arrays and single characters as arguments, and if your argument list is not too long, consider writing a few redundant replacement statements, passing one character at a time, instead of one line of code that accepts arrays as search and replace arguments.
- It’s better to use select statements than multi if, else if, statements.
- Error suppression with @ is very slow.
- Turn on apache’s mod_deflate
- Close your database connections when you’re done with them
-
$row['id']
is 7 times faster than
$row[id] - Error messages are expensive
- Do not use functions inside of for loop, such as
for ($x=0; $x < count($array); $x)The count() function gets called each time.
- Incrementing a local variable in a method is the fastest. Nearly the same as calling a local variable in a function.
- Incrementing a global variable is 2 times slow than a local var.
- Incrementing an object property (eg.
$this->prop++) is 3 times slower than a local variable.
- Incrementing an undefined local variable is 9-10 times slower than a pre-initialized one.
- Just declaring a global variable without using it in a function also slows things down (by about the same amount as incrementing a local var). PHP probably does a check to see if the global exists.
- Method invocation appears to be independent of the number of methods defined in the class because I added 10 more methods to the test class (before and after the test method) with no change in performance.
- Methods in derived classes run faster than ones defined in the base class.
- A function call with one parameter and an empty function body takes about the same time as doing 7-8
$localvar++operations. A similar method call is of course about 15
$localvar++operations.
- Surrounding your string by ‘ instead of “ will make things interpret a little faster since php looks for variables inside ”…” but not inside ‘…’. Of course you can only do this when you don’t need to have variables in the string.
- When echoing strings it’s faster to separate them by comma instead of dot. Note: This only works with echo, which is a function that can take several strings as arguments.
- A PHP script will be served at least 2-10 times slower than a static HTML page by Apache. Try to use more static HTML pages and fewer scripts.
- Your PHP scripts are recompiled every time unless the scripts are cached. Install a PHP caching product to typically increase performance by 25-100% by removing compile times.
- Cache as much as possible. Use memcached – memcached is a high-performance memory object caching system intended to speed up dynamic web applications by alleviating database load. OP code caches are useful so that your script does not have to be compiled on every request
- When working with strings and you need to check that the string is either of a certain length you’d understandably would want to use the strlen() function. This function is pretty quick since it’s operation does not perform any calculation but merely return the already known length of a string available in the zval structure (internal C struct used to store variables in PHP). However because strlen() is a function it is still somewhat slow because the function call requires several operations such as lowercase & hashtable lookup followed by the execution of said function. In some instance you can improve the speed of your code by using an isset() trick.Example:
if (strlen($foo) < 5) { echo "Foo is too short"; }vs.if (!isset($foo{5})) { echo "Foo is too short"; }Calling isset() happens to be faster then strlen() because unlike strlen(), isset() is a language construct and not a function meaning that it’s execution does not require function lookups and lowercase. This means you have virtually no overhead on top of the actual code that determines the string’s length.
- When incrementing or decrementing the value of the variable
$i++happens to be a tad slower then
++$i. This is something PHP specific and does not apply to other languages, so don’t go modifying your C or Java code thinking it’ll suddenly become faster, it won’t.
++$ihappens to be faster in PHP because instead of 4 opcodes used for
$i++you only need 3. Post incrementation actually causes in the creation of a temporary var that is then incremented. While pre-incrementation increases the original value directly. This is one of the optimization that opcode optimized like Zend’s PHP optimizer. It is a still a good idea to keep in mind since not all opcode optimizers perform this optimization and there are plenty of ISPs and servers running without an opcode optimizer.
- Not everything has to be OOP, often it is too much overhead, each method and object call consumes a lot of memory.
- Do not implement every data structure as a class, arrays are useful, too
- Don’t split methods too much, think, which code you will really re-use
- You can always split the code of a method later, when needed
- Make use of the countless predefined functions
- If you have very time consuming functions in your code, consider writing them as C extensions
- Profile your code. A profiler shows you, which parts of your code consumes how many time. The Xdebug debugger already contains a profiler. Profiling shows you the bottlenecks in overview
- mod_gzip which is available as an Apache module compresses your data on the fly and can reduce the data to transfer up to 80%
- optimizing-debugging php
PaaS PHP Fog Launches To The Public

Like a Heroku for PHP, PHP Fog is launching to the public today in order to help PHP developers deploy and scale their applications in the cloud. Raising $1.8 million in a round lead by Madrona and followed on by First Round, Founders Co-Op and others. PHP Fog launched in private beta in December and is now available for all members of the public.
Aside from focusing solely on PHP, what PHP Fog does differently than Heroku (and all encompassing competitor dotCloud) is that it provides users with an PHP app store, which lets people build out Drupal and WordPress sites without needing to know how to code. The service starts out as free with shared hosting and then ranges from $29 – $249 depending on how many servers you want dedicated.
Says founder Lucas Carlson, “When I started the company I thought, ‘Why isn’t anyone doing this for PHP, it’s a much bigger market?’ Out of the top one million webpages, 330K run PHP and and only 5K run Ruby. This is a much bigger opportunity, and I’ve been lucky because I’ve been able to cash in on this opportunity.”
Since its funding in December, PHP Fog has hired a team of developers (8) and signed up 13,000 people on its beta list; ”It took Heroku a year to sign up 10,000 people and it took us 6 months to sign up 13,000 people, so we’re going twice as fast.”
In addition to hiring and building out more applications, Carlson admits that a name change is in the cards (PHP Fog is the pretty much most boring startup name I’ve ever written about, and I wrote about Shwowp). He has big plans and eventually wants the service to be the “Amazon of PaaS.”
Rolling out to 1,000 people per day over the past week, PHP Fog is currently available for anyone who wants to sign up here.
[detikinet]
Running PHP on IIS 7
This post provides an step by step approach for deploying a PHP application on an IIS 7 server. The first thing that needs to be done is to make sure that IIS is installed on your machine. You can do this from the Turn Windows Feature On Off option in the Program and Features of Control Panel(In vista).

Here you need to make sure that in the Application Development Features ISAPI extensions and ISAPI Filters are also checked or if it is not check it and press OK. This will install the ISAPI extensions. Also make sure that Internet Information Services is checked.
Now the next step is to download PHP which is available at http://www.php.net/downloads. Or if you are using wamp already the C:/wamp/php works prefectly. You just need to make sure that the php folder contains php5isapi.dll file which is necessary for us.

Now open the php.ini file inside the PHP folder and edit it in a notepad to make the following changes if necessary. Remove the semicolor(;) from to make ;extension=php_mysql.dll to extension=php_mysql.dll and ;extension=php_mysqli.dll to extension=php_mysqli.dll.

You also need to add the location of your PHP directory to the server’s PATH environment variable so that Windows knows where to look for any PHP related executables (such as the PHP extension DLL‘s). To do this Right-click on My Computer, click Properties and on the Advanced tab click Environment Variables. In the Environment Variables dialog box, under System variables highlight the Path variable and click Edit.

Then add the location of your php file and the ext folder following it in the variable value.
Now go to Internet Information Services Manager in the control panel or run C:\windows\system32\inetsrv\inetmgr.exe to get the following screen.
Open the ISAPI filters link and click add.

Now fill the fields as given below.

Click OK, go back and open Handler Mappings and then click Add Script Map. Add the information as shown below i.e. specify the *.php extension and the path of php5isapi.dll file.

After you click ok you get another prompt. Click OK again and now you might need to reboot your PC for the changes to take effect. Or I think restarting IIS will be enough(Restarting IIS:Run->Services.msc->IISadmin).
Now take a php project or a php file. Just write in a file and save it as index.php in a folder(lets say TestPHP)

Now you can put the folder (TestPHP) in C:\inetpub\wwwroot. Now in the browser type http://localhost/TestPHP/index.php . The output will be like this:

Another approach is to create a virtual directory in the IIS default website. For this go the the IIS Manager via control panel.
Click on the default document icon->Add->Add index.php as a default document
Right click on the default website and click Add Application. Specify the physical path and the alias of the project folder.

Now type http://localhost/IISPHP on the browser and you will be getting the same output as above
[abcphp]
Creating Word, Excel and CSV files with PHP
- MS Word document
- Using HTTP headers
- Using COM objects
- Using OpenOffice templates
- Using Zend Framework component phpLiveDocx
- MS Excel document
- Using HTTP headers
- Using COM objects
- CSV file
- Using HTTP headers
- Using fputcsv()
How to create MS Word document
Method 1 – Using HTTP headers
- Create manually an ODT template with placeholders, like [%value-to-replace%].
- When instantiating the template with real data in PHP, unzip the template ODT (it’s a zipped XML), and run against the XML the textual replace of the placeholders with the actual values.
- Zip the ODT back.
- Run the conversion ODT -> DOC via OpenOffice command line interface.
Sending HTML Email Using PHP
Sending a Simple Text Email
Encrypt Passwords in the Database
<?php
define(“DB_SERVER”, “localhost”);
define(“DB_USER”, “your_name”);
define(“DB_PASS”, “your_pass”);
define(“DB_NAME”, “your_db”);
define(“TBL_USERS”, “users_table_name”);
$connection = mysql_connect(DB_SERVER, DB_USER, DB_PASS) or die(mysql_error());
mysql_select_db(DB_NAME, $connection) or die(mysql_error());
…
function addNewUser($username, $password){
global $connection;
$password = md5($password);
$q = “INSERT INTO “.TBL_USERS.” VALUES (‘$username’, ‘$password’)”;
return mysql_query($q, $connection);
}
?>
|
<?php
function checkUserPass($username, $password){ global $connection; $username = str_replace(“‘”,”””,$username) |
define(“DB_SERVER”, “localhost”);
define(“DB_USER”, “your_name”);
define(“DB_PASS”, “your_pass”);
define(“DB_NAME”, “your_db”);
define(“TBL_USERS”, “users_table_name”);
define(“FLD_USER”, “username_field_name”);
define(“FLD_PASS”, “password_field_name”);
set_magic_quotes_runtime(0);
$connection = mysql_connect(DB_SERVER, DB_USER, DB_PASS) or die(mysql_error());
mysql_select_db(DB_NAME, $connection) or die(mysql_error());
$q = “SELECT “.FLD_PASS.”,”.FLD_USER.” FROM “.TBL_USERS.”";
$result = mysql_query($q, $connection);
$total=0;
$enc=0;
$doencrypt=false;
if (@$_REQUEST["do"]==”encrypt”)
$doencrypt=true;
while($data = mysql_fetch_array($result))
{
if ($doencrypt)
{
$total++;
if (!encrypted($data[0]))
{
$q=”UPDATE “.TBL_USERS.” SET “.FLD_PASS.”=’”.md5($data[0]).”‘ where “.FLD_USER.”=’”.
str_replace(“‘”,”””,$data[1]).”‘”;
mysql_query($q, $connection);
}
$enc++;
}
else
{
$total++;
if (encrypted($data[0]))
$enc++;
}
}
function encrypted($str)
{
if (strlen($str)!=32)
return false;
for($i=0;$i<32;$i++)
if ((ord($str[$i])<ord(’0′) || ord($str[$i])>ord(’9′)) && (ord($str[$i])<ord(‘a’) || ord($str[$i])>ord(‘f’)))
return false;
return true;
}
?>
<html>
<head><title>Encrypt passwords</title></head>
<body>
Total passwords in the table – <?php echo $total; ?><br>
<?php if($enc==$total && $total>0) { ?>
All passwords are encrypted.
<?php } else if($total>0) { ?>
Unencrypted – <?php echo $total-$enc; ?><br><br>
Click “GO” to encrypt <?php echo $total-$enc; ?> passwords.<br>
WARNING! There will be no way to decipher the passwords.<br>
<input type=button value=”GO” onclick=”window.location=’encrypt.php?do=encrypt’;”>
<?php } ?>
</body>
</html>
Connect to MS SQL Server database
$myServer = “localhost”;
$myUser = “your_name”;
$myPass = “your_password”;
$myDB = “examples”; //connection to the database
$dbhandle = mssql_connect($myServer, $myUser, $myPass)
or die(“Couldn’t connect to SQL Server on $myServer”);
//select a database to work with
$selected = mssql_select_db($myDB, $dbhandle)
or die(“Couldn’t open database $myDB”); //declare the SQL statement that will query the database
$query = “SELECT id, name, year “;
$query .= “FROM cars “;
$query .= “WHERE name=’BMW’”; //execute the SQL query and return records
$result = mssql_query($query);
$numRows = mssql_num_rows($result);
echo “<h1>” . $numRows . ” Row” . ($numRows == 1 ? “” : “s”) . ” Returned </h1>”; //display the results
while($row = mssql_fetch_array($result))
{
echo “<li>” . $row["id"] . $row["name"] . $row["year"] . “</li>”;
}//close the connectionmssql_close($dbhandle);
?>
|
<?php
//connect to a DSN “myDSN” $conn = odbc_connect(‘myDSN’,”,”); if ($conn) echo “<table border=\”1\”><tr>”; //print field name echo “</td> </tr>”; |
|
<?php
$myServer = “localhost”; $myUser = “your_name”; $myPass = “your_password”; $myDB = “examples”; //create an instance of the ADO connection object$conn = new COM (“ADODB.Connection”) or die(“Cannot start ADO”); //define connection string, specify database driver$connStr = “PROVIDER=SQLOLEDB;SERVER=”.$myServer.”;UID=”.$myUser.”;PWD=”.$myPass.”;DATABASE=”.$myDB; $conn->open($connStr); //Open the connection to the database //declare the SQL statement that will query the database $query = “SELECT * FROM cars”; //execute the SQL statement and return records $rs = $conn->execute($query); $num_columns = $rs->Fields->Count(); for ($i=0; $i < $num_columns; $i++) { echo “<table>”; echo “</table>”; //close the connection and recordset objects freeing up resources $rs = null; |
USE examples;
CREATE TABLE cars(
id int UNIQUE NOT NULL,
name varchar(40),
year varchar(50),
PRIMARY KEY(id)
);
INSERT INTO cars VALUES(1,’Mercedes’,’2000′);
INSERT INTO cars VALUES(2,’BMW’,’2004′);
INSERT INTO cars VALUES(3,’Audi’,’2001′);
Using Cookies in PHP
- How to Create a Cookie?
- How to Retrieve a Cookie Data?
- How to Delete a Cookie?
- [name] The cookie name. The name of each cookie sent is stored in the superglobal array $_COOKIE.
- [value] The cookie value. It is associated with the cookie name.
- [expire] The time after which the cookie should expire in seconds
- [path] Specifies the exact path on the domain that can use the cookies.
- [domain] The domain that the cookie is available. If not domain is specified, the default value is the value of the domain in which cookie was created.
- [security] Specifies whether the cookie will be sent via HTTPS. A value of 1 specifies that the cookie is sent over a secure connection but it doesn’t mean that the cookie is secure. It’s just a text file like every other cookie. A value of 0 denotes a standard HTTP transmission.
setcookie(“myCookie”, “PHP Tutorial”, time()+3600, “/tutorials”);
?>
echo “The cookie value is “.$_COOKIE['myCookie'];
?>
setcookie(“myCookie”, “”, time()-60);
?>
Blogroll
Google Search :)
Calendar
Archives
- May 2013
- April 2013
- March 2013
- February 2013
- January 2013
- December 2012
- November 2012
- October 2012
- September 2012
- August 2012
- July 2012
- June 2012
- May 2012
- April 2012
- March 2012
- February 2012
- January 2012
- December 2011
- November 2011
- October 2011
- September 2011
- August 2011
- July 2011
- June 2011
- May 2011
- April 2011
- March 2011
- February 2011
- January 2011
- December 2010
- November 2010
- October 2010
- September 2010
- August 2010
- July 2010
- June 2010
- May 2010
- April 2010
- March 2010
Recent Posts
- Dropbox vs. Google Drive vs. Amazon vs. Skydrive: Which One Is Fastest ?
- Google And SAP: Two Very Different Cloud Strategies
- BlackBerry to offer BBM as standalone app for iOS and Android this summer
- Open Source Is Better Than the Closed Stuff (Until You Hit 1 Million Lines)
- Where In The World Is Your Next Data Center ?
- 10 Kiat untuk Programmer yang Mau Jadi Entrepreneur
- Review: The New Digital Age: Reshaping the Future of People, Nations and Business
- The New API Gold Rush
- Refurbished IT: A Cost-Efficient, Green Approach To Big Data
- Study: Social trumped email, news in time spent online in 2012

admin



