rss

Code Analyzers for PHP

Category : Featured, PHP

Code analyser functions:-

  • Checks code for error
  • Checks code for syntax 
  • Show linkages between various modules
  • Detects code duplication

Doxygen can be configured to render nice inheritance graphs with graphviz. It can help you in three ways:

  • It can generate an on-line documentation browser (in HTML) and/or an off-line reference manual (in ) from a set of documented source files. There is also support for generating output in RTF (MS-Word), PostScript, hyperlinked PDF, compressed HTML, and Unix man pages. The documentation is extracted directly from the sources, which makes it much easier to keep the documentation consistent with the source code.
  • You can configure doxygen to extract the code structure from undocumented source files. This is very useful to quickly find your way in large source distributions. You can also visualize the relations between the various elements by means of include dependency graphs, inheritance diagrams, and collaboration diagrams, which are all generated automatically.

phpCallGraph. is a tool to generate static call graphs for PHP source code. Such a graph visualizes the call dependencies among methods or functions of an application. Arrows represent calls from one method to another method. Classes are drawn as rectangles containing the respective methods. The graphs can be leveraged to gain a better understanding of large PHP applications or even to debunk design flaws in them.

PMDs duplicate code detection for PHP code. 

Yasca — Yet Another Source Code Analyzer, a plugin-based framework for scanning arbitrary file types, with plugins for scanning PHP and other file types. It integrates with other scanners, including FindBugs, JLint, PMD, and Pixy.

DMS

DMS Software Reengineering Toolkit — Supports custom analysis of PHP  and many other languages. Also COTS tools for clone analysis, dead code analysis, and style checking.

Fortify — Helps developers identify software security vulnerabilities in PHP as well as configuration files. 

Detects security flaws in PHP web applications

Analyzes PHP — reverse engineering of source, code navigation, and metrics tool.

Visualize and understand the application components & associations
Find way through the most complex code
Focus on coding, maximize your time 

Finds security flaws in application binaries and bytecode without requiring source.

Share

PHP forAndroid.apk HOWTO install and test

Category : Featured, PHP

The video shows how to install PHP on Amdroid and start building your PHP apps for Android

PHPforAndroid.apk HOWTO install and test from irontec on Vimeo.

Share

Namazu with PHP5 on Linux

1

Category : Featured, PHP

Namazu is a full-text search engine intended for easy use is what the namazu site tells its users. I have already worked on namazu and it worked amazingly fast. Recently i started working on a project having tens & thousands of records and it was cumbersome for MySQL to work efficiently under that much load. I decided to use namazu for that but unfortunately i was working on a windows based platform and its very difficult to configure PHP5 with namazu on windows. I was able to install namazu easily on windows. One can use the CGI mode to use namazu on windows but installing namazu as a PHP extension is difficult at least for me at this time.

But i was able to install namazu on LINUX and was also able to install namazu as a PHP extension on LINUX. While stumbling though site searching for installing namazu with PHP5 i got this link which describes how one can install namazu on LINUX and its PHP extension also.

I will keep on searching how to get namazu as a PHP extension, meanwhile you can use this link to get namazu working on LINUX.

Share

PHP Frameworks

Category : General, PHP

PHP Frameworks

While working with CakePHP & Zend i was excited to know more about what all other frameworks are available for PHP and compare them to see what suffice the need for a particular scenario. I found some good links but wikipedia was the best to provide me all the details of the frameworks, so here is a snap for all the PHP frameworks available.

Going forward i will be posting other frameworks for other scripting languages. So sit back any enjoy.

Project Language Ajax MVC framework MVC Push/Pull i18n & l10n? ORM DB migration framework(s)
Banshee PHP PHP 5 Banshee AJAX, jQuery/jQuery UI Yes Push No
CakePHP PHP Prototype/script.aculo.us, jQuery/jQuery UI, MooTools/MooTools more Yes Push Yes Active record pattern (CakePHP 1.x), Data Mapper Pattern (CakePHP 2.x) Yes
CodeIgniter PHP Prototype/script.aculo.us, jQuery/jQuery UI]] Modified active record pattern Push Yes framework extension No
eZ Components PHP No Yes Push Yes Yes Yes
Fusebox PHP Yes Not mandatory Push No, custom
Midgard PHP jQuery MidCOM Pull Yes Midgard datagard
phunction PHP 5 No Optional No No No
Qcodo PHP 5 built-in QControl Push Yes XML-based Inherent
Simple Pattern Framework PHP 5 No Yes Push Yes Active PHP No
Symfony PHP 5 Prototype, script.aculo.us, Unobtrusive Ajax with UJS and PJS plugins Yes Push Yes Propel, Doctrine (YAML) Plugin exists (alpha code, though)
Yii PHP 5 (>=5.1.0) jQuery, jQuery UI, own components Yes Push & Pull Yes Database Access Objects (DAO), Active Record Plugin
Zend Framework PHP 5 (>=5.2.4) Toolkit-independent Yes Push & Pull Yes Table and Row data gateway Yes
SilverStripe (Sapphire) PHP 5 (>=5.2) jQuery/jQuery UI Active record pattern Push & Pull Yes Active record pattern (Automatic)

PHP Framework

Project Current Stable Version Release Date License
CakePHP 1.3.3 2010-07-18 MIT
CodeIgniter 1.7.2 2009-09-11 BSD-style
Horde 3.3.8 2010-04-28 LGPL
Qcodo 0.4.16 2010-06-09 MIT
Seagull 0.6.7 2010-02-23 BSD
Symfony 1.4.6 2010-06-29 MIT
Yii 1.1.4 2010-09-05 BSD
Zend Framework 1.10.7 2010-07-30 BSD
Project Current Stable Version Release Date License
Share

Software Engineering In PHP

Category : Information, PHP

I was wondering if the PHP developers can work exactly like a JAVA developer in the sense the PHP developer has all the tools required for building, deploying & managing the application like a JAVA developer. Here i found a slide from Ralph & Josh who have given a very good details of all the things that you can use while developing a PHP app.

Share

PHP ORM: Doctrine 2

Category : PHP

At the start of my career as a developer, there were almost no ORM for PHP, there existed some classes that enabled you to easily access DB but not ORM.

ORM(Object Relational Mapping) in computer software is a programming technique for converting data between incompatible type systems in object-oriented programming languages. In other words it maps the relational database to the objects in your application. So each table becomes and object.

Doctrine is one of the powerful ORM present for PHP and with Doctrine 2 its has provided more features and ease of accessing database.

Share

CakePHP Migrations Plugin

1

Category : Application Design, PHP

I regularly read through http://cakedc.com/, they have lots of CakePHP plugin that i can use in my CakePHP development. I was facing some problems with cakePHP migrations, i am not saying that CakePHP does not support that but its not come by default with the framework, you have to put some efforts to get it done.
I came across this CakePHP migration plugin that seems to be very useful in keeping my DB migration manageable.

The Migrations plugin provides a comprehensive management system whereby the database schema for a CakePHP project can fluctuate during development involving any number of developers. This is achieved by incrementally managing database changes, providing customisable hooks and callbacks for data migration and changes to meet migration paths, and migration maps to provide flexible application of migration instances.

Migrations is great for any development team, or individual that wants to manage database schema and data changes throughout the development lifetime of a project.

Requirements

CakePHP 1.3 or higher.

If you need a version to use with CakePHP 1.2 please contact us directly.

You can download the plugin from CakeDC site http://cakedc.com/eng/downloads/view/cakephp_migrations_plugin

Share

CakePHP Paginate Count with group by

14

Category : General, PHP

I am working on a CakePHP project these days, today i ran into a different problem with CakePHP. Sometimes i feel that there are small-small things that are sometimes missed by the Cake developers, but thank God that there are some workarounds available to them.  Here is the problem statement that i encountered, i had a table in which i was having duplicate records and i wanted to show only distinct records in the data grid which was using the CakePHP paginator class to create a paginated data grid.

Now to show only the distinct rows i used the group by clause to eliminate the duplicate records, the records were coming fine but when i saw the paging it was not working right at all. The problem was that the paginator’s “paginateCount” function was also considering the “Group By” clause while doing the counting of the total records. This was crazy.

I searched through Google to get a solution to that and found this link, where people have already reported a his error to the cake developers. The solution that worked for me was that i needed to override the “paginateCount” function and use a different function in my model to get the correct number of total records. I added this function to my model and whola it worked for me. Here is the function that needs to be added model to get things right.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
public function paginateCount($conditions = null, $recursive = 0, $extra = array()) {
		$parameters = compact('conditions', 'recursive');
 
		if (isset($extra['group'])) {
			$parameters['fields'] = $extra['group'];
 
			if (is_string($parameters['fields'])) {
				// pagination with single GROUP BY field
				if (substr($parameters['fields'], 0, 9) != 'DISTINCT ') {
					$parameters['fields'] = 'DISTINCT ' . $parameters['fields'];
				}
				unset($extra['group']);
				$count = $this->find('count', array_merge($parameters, $extra));
			} else {
				// resort to inefficient method for multiple GROUP BY fields
				$count = $this->find('count', array_merge($parameters, $extra));
				$count = $this->getAffectedRows();
			}
		} else {
			// regular pagination
			$count = $this->find('count', array_merge($parameters, $extra));
		}
		return $count;
	}
Share

CakePHP Sharing sessions between apps on the same domain

1

Category : General, PHP

Few days back i was working on two separate CakePHP applications, suddenly there was a need to maintain session between these two separate apps working on the same domain. Let me explain a bit more.

Cake-logo
Cake-logo
Image via Wikipedia

I was having two apps (i)wishlist (ii) lighthouse

These are two separate apps under the root folder having the directory structure as:
/htdocs
/wishlist
/app
/config
….
/lighthouse
/app
/config ….

By default the sessions are created relative to the apps directory, and this was the problem i was dealing with, not a big thing but i spent a lot of time figuring this, but for you its will work like a charm.

Steps that i follow to make the two apps share sessions between them.
1. Edit “core.php” for wishlist and the lighthouse and add the line
ini_set(‘session.cookie_path’, “/”);
This is to direct the CakePHP app to create the session on the root

2. The Session.cookie name should be same for the two apps

3. The Session.salt should be same for the two apps

4. Security.level should be low in both the apps

This is it what is required. Let me know if you are still stuck with the things, happy coding.

Share

PHP: Fuzzy Address Matching Algo (Levenshtein)

Category : MySQL, PHP

Few days back i encountered a weird problem.
I had three tables in my DB viz: students, sites, company. Student table has the address fields and a column named “site_id” to connect it to the sites table. Sites table also has its address fields.

Now the challenge was to update the “site_id” field of the students table based on the matching address in the student and the site table. The address fields in both the tables were divided into following fields

  • address1
  • address2
  • city
  • state
  • country
  • zip

Now i had to think of a solution of how to do it. After googling a while i found a function called “levenshtein()” in PHP. This function calculated the distance between two given strings, bingo i got an idea and implemented the sddress matching algorithm. I have attached the file with this post.
Kindly let me if that was helpful to you.

Download the code from here -> fuzzy-match

Share

Amit Yadav is Stephen Fry proof thanks to caching by WP Super Cache