Archive

Archive for the ‘PHP Notes’ Category

Wordpress to Drupal Migration – Part 1

August 5th, 2010 Zareef Ahmed No comments

Recently I have done few projects where sites were growing rapidly in terms of functionalities and their current wordpress structure was not good enough to handle those changes. I am going to write about the summary of these personal experiences in this series of articles. I will summarize the steps and work I have done to do this migration.

Why Migration?

We should not do something because we can, should only do if need is there. So before starting it is necessary to understand if you really need the migration from Wordpress to Drupal. Wordpress is really a fantastic system and I have used the wordpress on website where we have done big customization and those sites were getting users visit in millions.

Following points can be considered and discussed with the team before finalizing migration :-
1. What is main purpose of migration?
2. What are the main problems which you are supposed to solve with migration?
3. Is there any available way in the current system using which current system issues can be solved?
4. What is the time different between estimation of migration and solving problem within current system?
5. do you see any future benefits in migration?
6. Do you have required skill set and resources to do the migration?
7. Are you migrating because you do not have resources to manage current system?

Gather answers for these questions and then analyze your situation.

In next part I will discuss what benefits Drupal can provide over a Wordpress system?

What you should know in wordpress to be a wordpress programmer?

February 20th, 2010 Zareef Ahmed No comments

I got several messages that I should point out a list of topics which a developer should know in wordpress to categorize him/her as a wordpress programmer.

“Wordpress Programmer” or “Wordpress Developer” terms can be new to someone but due its popularity, term is getting attention and several companies are doing hiring based on wordpress experience only.

So in this post I am just enlisting some points which a wordpress programmer should know.

  • How to install wordpress? (Yes it really easy but you should know that :) )
  • How to edit config file of wordpress if needed? You should also know what normally can be edited?
  • How to install a plugin in wordpress?
  • How to install a theme in wordpress?
  • How to modify a them in wordpress?
  • What are page templates?
  • How you can create/use a different template for archive or category page?
  • How you can use widgets?
  • How you can create a plugin?
  • How you can modify the content of a post or page?
  • How you can add something before or after a post/page content?
  • What are filters?
  • What are actions and how you can define callback functions on a particular action?
  • How you can create admin menu using plugins?
  • How you can edit the templates in online editor?
  • How you can manage widgets?
  • How you can manage users and thier different types?
  • How you can disable/enable comments on a wordpress site or on a specific page or post?
  • How you can use OPML files?
  • How you can import RSS feeds?
  • How you create custom meta tags in posts?
  • How you can add specific attributes to any post or page?
  • How you can mange user registration?
  • How you can create private blogs or posts?
  • At least 10-15 different plugins which can enhance/extend the basic wordpress functionality.
  • How you can use caching in wordpress?
  • How to upgrade wordpress?
  • How to take backup of wordpress posts using export?
  • How to take database backup of wordpress? (This can be classifieds as normall database backup process)

Above All

You should know what Wordpress CAN not do by default and what we should not try to do with it

Smarty Sponsorship : Nes Web Design now Sponsors Best PHP Template Engine Smarty

November 30th, 2009 Zareef Ahmed No comments

I am really feeling good by announcing that Nes Web Design (ONS Interactive Solutions Pvt. Ltd.), company with which I am working as CTO is sponsoring Smarty Template Engine, which in my view is the best Template Engine in PHP.Smarty helps a php developer in separating business logic from display logic.

It was year 2003 when I first got a chance to work with Smarty for a big project and today I am still proud of my decision.

Smarty is not just a presentation layer or tool to separate the html from programming code, it is in fact a complete system to handle display logic of your application. Smarty is so good at many things that many people call it a framework instead of template system. It has plug-in capacity,debug tool, programming construct, inbuilt shortcode, ability to extends functions, block level cache and so many other things, even you can use your php code in smarty template if need arise (although it is a bad practice).

Now something about my company Nes Web Design, Nes Web Design is a 9 years old company in the field of Web Design in India and I recently joined Nes Web Design as Chief Technology Officer. We are doing many projects on some industry standards like Zend Framework, Smarty and many more customized solutions.

We will continue our support to the open source movement.

PHP Functions to work with PHP functions

July 9th, 2009 Zareef Ahmed No comments

In this article, I am going to write about the functions using which you can get the information about php functions.

For a full list of PHP functions you can visit http://www.zend.com/phpfunc/

Using these functions you can query the stats/status of your functions, these functions are very useful in dynamic application creation.

For example, using func_get_arg and func_num_args functions you can simulate the function overloading in PHP.

Read a good example for http://www.dubi.org/php-function-overloading

Functions I will write in this article are :-

get_defined_functions();

You want to how many functions are in your installation of PHP, just call this function, it will return an array of all php functions you can call. For the convince it return an multidimensional array, so you can access both internal and user defined functions separately.

func_get_arg()

Returns the argument which is at the arg_num’th offset into a user-defined function’s argument list. Function arguments are counted starting from zero. func_get_arg() will generate a warning if called from outside of a function definition. This function cannot be used directly as a function parameter. Instead, its result may be assigned to a variable, which can then be passed to the function.
If arg_num is greater than the number of arguments actually passed, a warning will be generated and func_get_arg() will return FALSE.
As this function depends on the current scope to determine parameter details, it cannot be used as a function parameter. If you must pass this value, assign the results to a variable, and pass the variable.

func_get_args()

Returns an array in which each element is a copy of the corresponding member of the current user-defined function’s argument list. func_get_args() will generate a warning if called from outside of a function definition. This function cannot be used directly as a function parameter. Instead, its result may be assigned to a variable, which can then be passed to the function.
This function returns a copy of the passed arguments only, and does not account for default (non-passed) arguments.
As this function depends on the current scope to determine parameter details, it cannot be used as a function parameter. If you must pass this value, assign the results to a variable, and pass the variable.

func_num_args() Returns the number of arguments passed into the current user-defined function. func_num_args() will generate a warning if called from outside of a user-defined function. This function cannot be used directly as a function parameter. Instead, its result may be assigned to a variable, which can then be passed to the function.
As func_get_arg() this function also can not be passed as argument to another function.

function_exists()

Checks the list of defined functions, both built-in (internal) and user-defined, for function_name. Returns TRUE on success or FALSE on failure.

create_function()

Creates an anonymous function from the parameters passed, and returns a unique name for it. Usually the args will be passed as a single quote delimited string, and this is also recommended for the code. The reason for using single quoted strings, is to protect the variable names from parsing, otherwise, if you use double quotes there will be a need to escape the variable names, e.g. \$avar.

This is one of very useful function to create dynamic application, using this function you can create the function at run time and then use them as per your requirements.

call_user_func()

Call a user defined function given by the function parameter.
People are divided on the use of this function, some thinks that it is not needed at all when we can run the function on the variable itself.
Like use of this function is

function test($value)
{
print "This is $value";
}

call_user_func("test","test value");

some people prefer using variable function like this :-

$funcname="test";
$funcname("test");

This is also a call_usr_func_array function.

is_callable()

If you are going to use a a variable function like previous example, you may need to verify if a function already present and callable? using this function you can do that.
This function Verify that the contents of a variable can be called as a function. This can check that a simple variable contains the name of a valid function, or that an array contains a properly encoded object and function name.
The var parameter can be either the name of a function stored in a string variable, or an object and the name of a method within the object, like this:

array($SomeObject, 'MethodName')

In some way it is similar to function_exisits function but it does more that that if you just want to check the syntax then you can pass a second argument as True, in that case it only verifies that var might be a function or method. It will only reject simple variables that are not strings, or an array that does not have a valid structure to be used as a callback. The valid ones are supposed to have only 2 entries, the first of which is an object or a string, and the second a string.

PHP is a functional language and you can almost do anything with these functions.

Tags:

Use Exit after redirecting user via header function

June 18th, 2008 Zareef Ahmed No comments

Some weeks ago I got an old PHP application to work with. I was asked to look for the potential problems and bottlenecks in the application. So I decide to use APD as a profiler for the application, after installing the APD on that server. I enabled profiler on one of the reportedly slow page.

That page was meant to be displayed and executed only if user is logged in and session variables are set. If we don’t found user session then user was being redirected to Login page of the application.

I called that page directly in the browser and got the login screen. It was perfectly acceptable behavior.

BUT when I run the profiler to get the information about the execution of page I was surprised to see that almost all functions which were only meant to be executed for logged in users were being called and they were taking the system resources.

Just to confirm I refresh the page in browser many time (without login), and each time I got same profile information for page.

Then I run the test using Apache benchmark (ab) and while test was in running I decide to see the process list of mysql database, again I see that heavy queries were being fired on the database. (But this time I was not surprised, as it was expected and I did just to confirm and take the screen shot so I can show that to the owner of the application.)

Now I decide to check the reason behind this, so I opened that page in my Zend Studio, and yes I got the reason …

Application was redirecting the user to login page if user is not logged in using header function via location define mechanism Like

  header("location: login.php");

And they were not using exit after that. I just add the exit(); after that header function call and problem was fixed.

header("location: login.php");
exit();

Just an improper use of header was the reason behind unnecessary load on the web server as well as on database server.

Note : If you do use the location setting of the header to redirect to another page, do not forget to use “exit;” to prevent further execution of script code.

Tags:

PHP Development Notes

June 17th, 2008 Zareef Ahmed No comments

While writing PHP code or planning an application to be written in PHP, Every other day we have to face different aspects of programming, and we also need to find the work around or solutions to the problem we got during our development work.

Many times I surf the online pages of PHP manual to solve my problems and I found comments by other people very useful, so I have decided to compile the list of notes I normally took while working on the project.

Hope this will help someone someday in some situation :)

Tags:

If Suggested By Nata

December 11th, 2004 Zareef Ahmed No comments

If you can keep your head when all about you

Are losing theirs and blaming it on you;

If you can trust yourself when all men doubt you,

But make allowance for their doubting too;

If you can wait and not be tired by waiting,

Or, being lied about, don’t deal in lies,

Or, being hated, don’t give way to hating,

And yet don’t look too good, nor talk too wise;

If you can dream – and not make dreams your master;

If you can think – and not make thoughts your aim;

If you can meet with triumph and disaster

And treat those two imposters just the same;

If you can bear to hear the truth you’ve spoken

Twisted by knaves to make a trap for fools,

Or watch the things you gave your life to broken,

And stoop and build ‘em up with wornout tools;

If you can make one heap of all your winnings

And risk it on one turn of pitch-and-toss,

And lose, and start again at your beginnings

And never breath a word about your loss;

If you can force your heart and nerve and sinew

To serve your turn long after they are gone,

And so hold on when there is nothing in you

Except the Will which says to them: “Hold on !”;

If you can talk with crowds and keep your virtue,

Or walk with kings – nor lose the common touch;

If neither foes nor loving friends can hurt you;

If all men count with you, but none too much;

If you can fill the unforgiving minute

With sixty seconds’ worth of distance run -

Yours is the Earth and everything that’s in it,

And – which is more – you’ll be a Man my son!

—————– By Redyard Kipling

Tags:

Why This Homepage?

November 17th, 2004 Zareef Ahmed No comments
Zareef Ahmed

Zareef Ahmed

Why should I design and develope a homepage? This question struck me on the very first day when I decided to register a domain name for my own homepage. The first reason for developing one is the word ‘HOMEPAGE’ to attach to this.

Who wants to be a homeless person…? I decided to develop a homepage because I just refuse to be homeless on the Internet.

But after registering the domain… a big question arose what should I present to visitors of my homepage? At that time I was not sure if anyone will ever visit my homepage …… I just made one page and wrote something about me in around 100 words and put it on world wide web.

Fortunately, I was surprised to see that visitors started browsing my homepage. There was nothing for them but four links to my other webpages on which I maintain a small collection of links about LINUX, MySQL, PHP and XML.

With visitors, came the sense of responsibility that I should be more helpfull to my visitors, so I added a ‘Usefull Links’ section on my homepage…. and the result was expected ..The number of visitors kept on increasing after that. …. Google, Yahoo, MSN, Altavista, Lycos and many other search engines were very kind to me as they put my home page on top positions for many keywords and phrases.

One thing I would like to mention is my contemporary situation at the time of that homepage launch. I was completely broken and really homeless in this world….. I was away from parents and every good thing in my life except my lovely wife and small child.

Today I am quite established in life again……once programming was my hobby, today it is my profession.

I think very few persons in this world have this opportunity.

This homepage played a vital role in my revival. My revival? It is a long story, hope one day I will be in position to write about that.

Till then you can browse my home page. Currently I added some pages (including this one), they contain information about my recent projects and something about me in details.

I know some persons can treat this home page as a self-praising campaign. I have to admit it …yes I am self-praising because I sincerely think every person should concentrate on his/her positive things…… and if you have a quality then why not to tell it to others?…… well, there is a saying “Quality Speaks Itself”……. light will throw its rays in darkness…. etc etc… But Sorry ! I am not a subscriber to this idea.

See if I had not made this homepage would you ever be able to know of me?

This does not mean I never pay attention to my weaknesses…. The best thing I can do to my weak points is to eradicate them from my personality. So if I know something is wrong with me I will try to make it right.

But you have a right to tell what is wrong with me or my works that’s why I have created a contact page on the site. Please Please Please help me in eradicating wrong in me so I can be more right to you and every visitor of my site.

Got a wrong in me – do not hesitate to tell me right now, an answer guaranteed.

Tags: