February 9, 2010
February 9, 2010
February 9, 2010
I recently had the problem that I wanted to retrieve the smallest items from a stream of data. When talking about a stream here, I refer to a data set that I do not want to load into memory completely, since it has quite a few elements. The best way to process such data is a stream approach, where you work always on a single item at a time, iteratively, without loading the full data set.In my special case, I had a database with 140,000 records. The processing of these records could not happen in the DB, since I needed to create vectors from text and perform calculation on these. Basically, I needed to check each vectors distance to a reference vector and keep only the k closest ones.So, what is a good approach to solve such a task? I decided to implement a custom data structure based on a max heap to solve the problem. In this article, I present the solution and compare it to two different other approaches in terms of a small benchmark.
February 8, 2010
If you’re anything like me, you’d sooner forgo water than Firebug when working on a web project. The little ’bug is a fantastically useful HTML/CSS/JavaScript/Ajax debugger. But did you know it can also be used to debug PHP? Yes, thanks to an additional Firefox extension called FirePHP.
By combining this extension, which sits on top of Firebug, with a server-side library, your PHP scripts will be able to send debugging information to the browser, handily encoded in the HTTP response headers. Once you’re set up, you can log warnings and errors in your PHP scripts to the Firebug console, just as if you were developing JavaScript.
To start, you first need to install the FirePHP extension from Mozilla’s Firefox Add-ons site. This requires that you already have Firebug installed. Once FirePHP is installed, when you next open your Firebug panel, you’ll now see an additional blue bug. Click on that bug and a menu will appear allowing you to enable or disable FirePHP:

This, of course, won’t do anything yet. You also need to install the FirePHP server-side library, which is available here. This is a stand-alone version of the library that can either be downloaded manually or installed using PEAR. After that, you simply need to include the library in your code. There are also versions designed to integrate with various frameworks or content management systems, such as the WP-FirePHP plugin for WordPress or the JFirePHP plugin for Joomla. For the sake of this walk-through, I’ll focus on the stand-alone functionality.
Once you have the FirePHP library on your server, you need to include it in your script with a line like:
require_once('FirePHPCore/fb.php');
Because FirePHP sends its logging data via the HTTP headers, you’ll need to buffer your script’s output so that the response headers can include content generated further down the script. In PHP, this is accomplished by calling ob_start near the top of your script:
ob_start();
With these steps done, you can start using FirePHP. All you need to do is call the fb function with whatever you’d like to log, along with an optional label and an optional constant to define the message as a standard log, a warning, an error, or information. For example:
$var = array('a'=>'pizza', 'b'=>'cookies', 'c'=>'celery');
fb($var);
fb($var, "An array");
fb($var, FirePHP::WARN);
fb($var, FirePHP::INFO);
fb($var, 'An array with an Error type', FirePHP::ERROR);
This code will produce the following output in the Firebug console:

You can also use FirePHP to give you a trace of your application’s execution: by passing in the FirePHP::TRACE constant, you’ll get to see the line number, class name, and function name from within which fb was called. So this code:
function hello() {
fb('Hello World!', FirePHP::TRACE);
}
function greet() {
hello();
}
greet();
Will produce an output as follows:

This trace functionality can be fantastic for debugging more involved scripts, as it lets you know exactly from where your functions are being called.
Of course, you need to remember to remove your debugging statements before your code goes live!
There’s a lot more to FirePHP than what I’ve covered here. I’ve been showing you the simplified procedural API for FirePHP, but there’s a more advanced object-oriented API available with a number of additional features. You can learn all about it on the FirePHP site, so be sure to check it out.
Related posts:
- FireBug 0.4 includes JavaScript Debugger
- Useful in-browser development tools for PHP
- Introducing php-tracer-weaver
February 8, 2010
It can register new users, confirm user registrations, authenticate existing users and retrieve user password to send by e-mail as reminders.
The user records are stored in database. The queries to perform each user record database access are defined in a XML configuration file.
Features list:
# Open or closed registration, via master password;
# User role support;
# Live authentication (changing session unique id from one request to another);
# Password recovery OR reset support;
# Hack prevention built-in system:
* logs user out when obsolete session id is used;
* logs user out if IP address changes from one request to another;
* logs user out when session lifetime times out;
* auto-locks user on too many failed login attempts; locks are IP-based and can be reset by master.
# Easy to configure, via external XML files (provided by ParamsProxy package, see dependencies);
# SQL injections proof, thanks to built-in database traffic encoding/decoding mechanism (provided by DbProxy package, see dependencies).
February 8, 2010
It defines a base class that assigns values to variables of existing and future objects of derived classes.
February 8, 2010
February 8, 2010
One of the more common problems that many organizations face is the perception of performance in their web application. Or rather, the lack of it.
With this webinar we will take a look at several different performance “best practices” and also look at some ways you can analyze what is happening on your server. Not only will we look at PHP, but we will look at several different links in the execution chain, all of which can negatively or positively affect the performance of your website.
February 8, 2010
Zend Server 5 takes PHP performance and troubleshooting to a new level. With job queue you can schedule recurring tasks or offload long-running scripts to other servers for improved resource utilization. With code tracing you can quickly debug issues without having to reproduce problems, even when they occur in production!
Join us for a walkthrough and live demonstrations of the Zend Server 5.
February 7, 2010
It is an abstract class that provides access to retrieve values of private and protected variables while preventing to change those variables values.
Variables with names that start with an underscore still cannot be accessed from outside the class.
February 7, 2010
It can process a set of PHP scripts and generate equivalent ones obfuscated by removing comments and whitespace, renaming class names, constants and variables to obfuscated names, as well the references to those names.
The resulting processed PHP scripts are stored in a targeted directory.
February 6, 2010
It can add tags to a document using fluent interface calls that return the class object, so the calls can be nested.
The class provides functions to add most types of HTML tags.
The class returns the composed document as a string. The generated HTML can be made XHTML compliant.
February 6, 2010
It can store in control file the state of the currently running script.
The class can check that file to see if an instance of the script is already running to prevent that more than one instance of the script is being executed.
It can also check if another control file exists as a flag indicating that another script instructed the current instance to stop and exit.
February 6, 2010
February 6, 2010
I recently had the problem that I wanted to retrieve the smallest items from a stream of data. When talking about a stream here, I refer to a data set that I do not want to load into memory completely, since it has quite a few elements. The best way to process such data is a stream approach, where you work always on a single item at a time, iteratively, without loading the full data set.In my special case, I had a database with 140,000 records. The processing of these records could not happen in the DB, since I needed to create vectors from text and perform calculation on these. Basically, I needed to check each vectors distance to a reference vector and keep only the k closest ones.So, what is a good approach to solve such a task? I decided to implement a custom data structure based on a max heap to solve the problem. In this article, I present the solution and compare it to two different other approaches in terms of a small benchmark.


