A sample text widget

Etiam pulvinar consectetur dolor sed malesuada. Ut convallis euismod dolor nec pretium. Nunc ut tristique massa.

Nam sodales mi vitae dolor ullamcorper et vulputate enim accumsan. Morbi orci magna, tincidunt vitae molestie nec, molestie at mi. Nulla nulla lorem, suscipit in posuere in, interdum non magna.

Class flags with bitwise operators

There is a group of PHP features that most of developers don’t usually use: bitwise operators.

These operators are widely used in the C language to make low-level applications (device drivers, protocols etc..). They are very useful when used in OOP developing as a flags for options in functions, classes and general settings.

Brief overview

[...]

Simple PHP script to edit front end components

I’ve recently built a very simple web site. The only dynamic requirement was having some parts of the front end editable (WYSIWYG) by an administration area (user and password). Basically, a very simple basic CMS for one user.

SolutionA MySQL database is not needed, saving to files is much more appropriate for these requirements. Also [...]

PDO example

try { $pdo = new PDO(“mysql:host=127.0.0.1;dbname=dev;”,”root”,”" ); #$pdo>setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING); $pdo>exec(“DELETE FROM `User` WHERE id293968 “); #insert $insertedRows = $pdo>exec(“INSERT INTO `User` (username, password) VALUES (‘elvis’,'ciotti’) “); $lastInsertId = $pdo>lastInsertId(); echo “Inserted $insertedRows rows [id = $lastInsertId]\n”; $pdo>exec(“DELETE FROM `User` WHERE id=$lastInsertId “); #fetch foreach ($pdo>query(“SELECT * FROM `User` “, PDO::FETCH_ASSOC) as $row){ echo “{$row['id']}:{$row['username']}\n”; [...]

Simple effective PHP debugging + backtracking

During PHP debugging I often need to debug complex data. Is not always possibile to use Xdebug and the IDE debugging features with MVC frameworks, and also some arrays/object are too big and unhandy for FirePHP.

A valid solution might be a traditional “print_r”/”var_dump” + “exit”Two problems:1) accidental commits to the staging/production environment.2) it takes [...]

printing the backtrace in a complex PHP application

the PHP debug_backtrace [man] function is very useful to understand where a function/method is called.

It prints the back trace of the code.

Example: [...]

An idea for DB server load balancing

If the application has a heavy load of reading queries and there are no problems with the application requirements, a simple possible idea to balance the db server loading is to run the INSERT/UPDATE/ALTER queries in all the servers and run the SELECT queries in just one server (chosen randomly). Have a look at [...]

Compare Files between two directories recursively – PHP script

In this post I’ll present my PHP class to show differences (file missing or different file date) between files in two directories (recursively). It’s useful to compare two websites (Example, test and live versioning the same server) and show the differences, much faster than a FTP synchronization, and customizable (size differences instead of time, PHP [...]

benchmark: boolean variables value check

$a = NULL;

$t = microtime(true);for($i = 0; [...]

benchmark: array_key_exists vs isset

When the aim is to check if the element exists in an array and has a value not null, better to use isset(array[index]), that is much faster than array_key_exists(index, array). #PHP 5.3.0 command line – Amd turion 64 1.6 Ghz #create array$a = array();for($i = 0; [...]

array_walk example

bool array_walk ( array &$array , callback $funcname [, mixed $userdata ] )

/* example !! * transform array with other arrays as elements into an array with simple elements * array trasform ! */

$ar = array( array(1,2), array(10,20), array(100,200) );function sum(&$ar) //NOTE: Argument By reference{ $ar = $ar[0]+$ar[1];}

array_walk($ar, “sum”);print_r($ar);/* Array( [...]