Pages

Monday, May 7, 2012

Zend Framework - Dispatch process overview


PHP Interview Questions



1.     why go for php? major advantage? MVC?
PHP (recursive acronym for PHP: Hypertext Preprocessor) is a widely-used open source general-purpose       scripting language that is especially suited for web development and can be embedded into HTML
There are three main areas where PHP scripts are used
1. Server-side scripting. This is the most traditional and main target field for PHP. You need three things to make this work. The PHP parser (CGI or server module), a web server and a web browser. You need to run the web server, with a connected PHP installation. You can access the PHP program output with a web browser, viewing the PHP page through the server
2. Command line scripting. You can make a PHP script to run it without any server or browser. You only need the PHP parser to use it this way. This type of usage is ideal for scripts regularly executed using cron (on *nix or Linux) or Task Scheduler (on Windows). These scripts can also be used for simple text processing tasks
3.Writing desktop applications. PHP is probably not the very best language to create a                       desktop application with a graphical user interface, but if you know PHP very well, and             would like to use some advanced PHP features in your client-side applications you can     also use PHP-GTK to write such programs. You also have the ability to write cross-   platform applications this way. PHP-GTK is an extension to PHP
Advantages
1. PHP is flexible. Use OOP or not. Use naming convention(s)
2. Very Easy to understand Syntax, some really cool features (arrays are something else!)
3. Ease transition to PHP from some other languages
4. PHP is flexible. we can Use OOP ,naming convention(s)
5.It runs on many different operating systems(Linux,windows,Unix)
6. It can be optimized, even "compiled" for performance closer to that of more established compiled languages
7. Pretty easy to access other web-based tools through PHP (i.e. google maps, etc.)
Open Source
 
PHP is an open source language and is freely available for use. The community of open source PHP developers provides technical support and is constantly improving updating the core PHP functionalities. The PHP Extension and Application Repository system provides and maintains a library of PHP code packages that are available for use. The packages can include functions such as authentication, caching, destructors, encryption, error handling etc.
Compatability
PHP provides high compatibility with leading operating systems and web servers such as thereby enabling it to be easily deployed across several different platforms.
 File Handling
PHP be used to read text and generate files in various formats such as PDF and XML. Using the file manipulation functions, files and documents can be uploaded and stored on the server. The uploaded documents can be accessed and manipulated through PHP code. PHP can be used to access flat files and perform basic file and directory maintenance tasks thereby enabling files/documents to be edited remotely.
 Improved Performance
The PHP complier includes features to optimize and improve the quality of compiled code by reducing the size execution time of the code thereby leading to improved performance. The compiled PHP code can be cached using various PHP accelerators such as xcache, eAccelerator etc thereby reducing time spent in parsing and compiling the code every time.
 Debuggers
Several debuggers are available with PHP enabling developers to identify and analyze the code for potential bugs and bottlenecks.
Sessions
PHP provides extensive session and cookie management features and functions enabling the creation and development of personalized web pages.
Graphics
PHP can be used to generate images and graphics dynamically. Using the image functionalities available with PHP, the header information of images an be accessed and manipulated. The GD library of PHP includes a host of features and functionalities that can be used to create images in various formats such as gif, jpeg and png.
Extensible
The source code of PHP can be modified to include custom created extensions and components thereby increasing its extensibility.

Disadvantages:
1. Out of the box, PHP tends to execute more slowly than assembly, C, and other compiled languages    
2. Security flaws due to unknown vulnerabilities .
3. Not good to create desktop Applications

MVC Pattern

 

 
The main aim of the MVC architecture  is to separate the business logic and application data from the presentation data to the user.
Here are the reasons why we should use the MVC design pattern.
1.     They are resuable : When the problems recurs, there is no need to invent a new solution, we just have to follow the pattern and adapt it as necessary.
2.     They are expressive: By using the MVC design pattern our application becomes more expressive.
1).  Model: The model object knows about all the data that need to be displayed. It is model who is aware about all the operations that can be applied to transform that object. It only represents the data of an application. The model represents enterprise data and the business rules that govern access to and updates of this data. Model is not aware about the presentation data and how that data will be displayed to the browser.  
2). View : The view represents the presentation of the application. The view object refers to the model. It uses the query methods of the model to obtain the contents and renders it. The view is not dependent on the application logic. It remains same if there is any modification in the business logic. In other words, we can say that it is the responsibility of the of the view's to maintain the consistency in its presentation when the model changes.
3). Controller:  Whenever the user sends a request for something then it always go through the controller. The controller is responsible for intercepting the requests from view and passes it to the model for the appropriate action. After the action has been taken on the data, the controller is responsible for directing the appropriate view to the user. In  GUIs, the views and the controllers often work very closely together.

  • 2.How to MVC works in zend, what are the components will support?

    Zend_Application, Zend_Application_Bootstrap, Zend_Application_Module, Zend_Application_Resource
  • Zend_Controller_Front, Zend_Controller_Action, Zend_Controller_Dispatcher, Zend_Controller_Plugin, Zend_Controller_Router
  • Zend_Form
  • Zend_Layout, Zend_View, Zend_View_Filter, Zend_View_Helper
The above components make use of the industry standard web application design pattern MVC (which originated with one of the first scripting languages ever built, Smalltalk), and allows developers and web designers to separate their concerns and skills, making code implementation and design easily and clearly separated. No more confusion or needing both skill sets in one person.

3. Zend components?
Model-View-Controller (MVC)

  • Zend_Application, Zend_Application_Bootstrap, Zend_Application_Module, Zend_Application_Resource
  • Zend_Controller_Front, Zend_Controller_Action, Zend_Controller_Dispatcher, Zend_Controller_Plugin, Zend_Controller_Router
  • Zend_Form
  • Zend_Layout, Zend_View, Zend_View_Filter, Zend_View_Helper
The above components make use of the industry standard web application design pattern MVC (which originated with one of the first scripting languages ever built, Smalltalk), and allows developers and web designers to separate their concerns and skills, making code implementation and design easily and clearly separated. No more confusion or needing both skill sets in one person.
Tooling and Rapid Application Development (RAD)
  • Zend_CodeGenerator
  • Zend_Reflection
  • Zend_Tool_Framework, Zend_Tool_Project
One of the most tedious tasks in any project is the initial application setup. Zend_Tool provides tooling support and a command-line client that allows you to generate your project structure, MVC artifacts, and more. Start writing your application immediately, instead of manipulating your directory tree.
Database
  • Zend_Db, Zend_Db_Adapter, Zend_Db_Profiler, Zend_Db_Select, Zend_Db_Table
Again using standard database programming best practices, data adapters for all major databases abstract away the details, so you can build your application (domain of your business) models on whatever database engine you need.
Internationalization (i18n) and Localization (l10n)
  • Zend_Currency
  • Zend_Date
  • Zend_Locale
  • Zend_Measure
  • Zend_Translate
In an increasingly global economy, localizing your application for a particular language and culture is imperative, not an afterthought. Do that easily, whenever you're ready to expand your markets, with Zend Framework's support for internationalization (i18n).
Authentication, Authorization, and Session management
  • Zend_Acl
  • Zend_Auth
  • Zend_Session
Virtually all web applications have some user-specific data that must be customized, and usually, protected from access by other users. Accomplish this quickly and easily with the above features of Zend Framework.
Web and Web Services
  • Consuming services: Zend_Feed, Zend_Gdata, Zend_Http_Client, Zend_Rest_Client, Zend_Service, Zend_XmlRpc_Client
  • Exposing services: Zend_Amf_Server, Zend_Json_Server, Zend_Server_Definition, Zend_Server_Reflection, Zend_Rest_Server, Zend_Soap_Server, Zend_XmlRpc_Server
Web services are an integral part of Zend Framework and we intend for Zend Framework to be the nexus for and entire eco-system of Web Services and APIs providers. We currently have partnered with Google, Microsoft, and StrikeIron and they have built support for their services into Zend Framework. More are coming soon.
Mail, Formats, and Search
  • Zend_Json
  • Zend_Mail, Zend_Mime
  • Zend_Pdf
  • Zend_Search_Lucene
Web 2.0 applications require support for Ajax, PDF generation, e-mail communication, and search, all an increasingly important part of web applications today. Zend Framework simplifies a developers life and gives you built-in support for these essential, if not critical, features for your application.
Core Infrastructure
  • Zend_Cache, Zend_Config, Zend_Console_Getopt, Zend_Debug, Zend_Filter, Zend_Loader, Zend_Loader_Autoloader, Zend_Log, Zend_Memory Zend_Registry, Zend_Validate, Zend_Version
Zend Framework is a broad library of loosely-coupled, yet highly cohesive pieces that support many of the other features you might need for a web application. From logging for tracking and debugging your application in production, caching for high performance, filtering for more secure and safe applications, to all the other little pieces that make a web application developer's life easy, Zend Framework provides all this, plus a vast community, a company standing behind and sponsoring development, and a large number of talented developers who know how to build Zend Framework applications from the ground up.
4.How do u debug the PHP code?
the code debugger is a tool that has almost all programing enviroments which allows you to watch the internal work of your applications and finding errors at run time for a easy way. The trouble is when you are working in a client-server architecture model, because from where you send the request (client) can not access the code hosted on the server.
To PHP exists any debuggers that require an installation in the server part, that can not always like you. However you can find useful tools that can help you to make this task without to be debugger exactly


FIRE PHP
FirePHP is a Mozilla Firefox complement that merges with Firebug and allows you to watch the outputs sent from PHP code in the console, so, you can watch the variables values or create a log about that is happened in your scripts without use the upset “echo” that interferes with you HTML.

The way FirePHP works is very easy, all the information that you want to view at run time is coded in JSON and sent in the headers of the response. When these headers arrives to the navigator, FirePHP detect it and to render the information in the Firebug console.
    FirePHP::LOG
    FirePHP::INFO
    FirePHP::WARN
    FirePHP::ERROR
    FirePHP::DUMP
    FirePHP::TRACE
    FirePHP::EXCEPTION
    FirePHP::TABLE

5.How can we have the separate php.ini file for multiple projects in same server?
Replace the system php.ini entirely

1.     To replace the system php.ini entirely, create a file under .php/5.3/ called "phpini". If this file exists, PHP will not read the system php.ini at all, so you should probably start by copying /etc/php53/php.ini here as a starting point. In most cases, this file is not necessary — please use a phprc if at all possible.
2.     You may need to force PHP to reload its configuration file for changes to take effect. You can do this by running "killall php53.cgi" from a shell, or by waiting several minutes.
Related forums
I want to set the include_path variable in my php.ini file (C:\Windows\php.ini).
But, I want different include_path values for different sites hosted on the same Windows server. How can I do this?
Ans :1
You can set the php include_path from an .htaccess file, assuming you have the correct AllowOverride settings in your httpd.conf file. Here's an example how:
.htaccess
php_value include_path "d:\path\to\include"

Ans:2
You can review this list and see if one of the techniques helps in your case. For example, you can set the environment variable PHPRC, or you can put a different php.ini file in each current working directory, assuming each virtual host has a distinct cwd.
Note that when using Apache and mod_php, or other module embedding PHP in the web server (e.g. FastCGI), the php.ini file is read once, at web server startup. When you use PHP in a CGI manner, the php.ini file is read during every web request, so you have more opportunity to use a different php.ini.
Disable Use Of Custom PHP.INI files On cPanel Server
When compiling Apache using cPanel’s EasyApache application, you have the option of installing ‘Mod suPHP’, which is just one of many options that make your php installation more secure when hosting multiple sites on the same server; e.g. shared hosting server.
When you have Mod suPHP installed, you can configure your server to force the use of the main server wide php.ini file and disable the use of custom php.ini files to adjust certain php settings. To do this:
1. Login to your server as root via SSH
2. Open the following file:
nano /opt/suphp/etc/suphp.conf
3. Search for [phprc_paths] and then uncomment (remove the ; from the front) the following lines:
;application/x-httpd-php=/usr/local/lib/
;application/x-httpd-php4=/usr/local/php4/lib/
;application/x-httpd-php5=/usr/local/lib/

Save the file, exit the editor, and then restart Apache

Important Note

Some popular modern php applications require quite generous php resource allowances(memory, to function, so it you enable this limitation, you need to make sure you have configured your default, server wide php.ini with settings that will these applications to run without issues.

6.Frequently used Php.ini settings

1a) Configure PHP settings with a php.ini file

php.ini specifies the configuration settings PHP will use when it is running on your website. It determines what things PHP scripts are allowed to do and what they are prohibited from doing. The following settings affect security.
In your public_html (the same folder where your site's main home page is), create a text file called php.ini that contains these lines. Instructions for customizing the text shown in red are farther down this page:
allow_url_fopen = Off
display_errors = Off
display_startup_errors = Off
log_errors = On
error_reporting = E_ALL
error_log = /home/yourUserID/public_html/phperr.txt
expose_php = Off
magic_quotes_gpc = On
magic_quotes_sybase = Off
register_globals = Off

1b) Alternative: configure PHP in .htaccess

If your webhost does not allow you to create your own php.ini, you can put configuration commands in .htaccess instead. Unfortunately, not all php.ini commands have .htaccess equivalents, but some of them do.
Put the following lines in a part of your public_html/.htaccess file that is not delimited by HTML-style tags such as the <Files></Files> tags in the example in Section 3.1 below. The following lines have the same effects as their php.ini counterparts described in Section 1a) above, but notice that the format of the commands is different:
php_flag display_errors Off
php_flag display_startup_errors Off
php_flag log_errors On
php_flag magic_quotes_sybase Off
php_flag magic_quotes_gpc On
php_flag register_globals Off
php_value error_log /home/yourUserID/public_html/phperr.txt
php_value error_reporting 2147483647

The most important is the register_globals line.

Here we are explaining the important settings in php.ini which you may need for your PHP Parser.

short_open_tag = Off

Short open tags look like this: <? ?>. This option must be set to Off if you want to use XML functions.

safe_mode = Off

If this is set to On, you probably compiled PHP with the --enable-safe-mode flag. Safe mode is most relevant to CGI use. See the explanation in the section "CGI compile-time options". earlier in this chapter.

safe_mode_exec_dir = [DIR]

This option is relevant only if safe mode is on; it can also be set with the --with-exec-dir flag during the Unix build process. PHP in safe mode only executes external binaries out of this directory. The default is /usr/local/bin. This has nothing to do with serving up a normal PHP/HTML Web page.

safe_mode_allowed_env_vars = [PHP_]

This option sets which environment variables users can change in safe mode. The default is only those variables prepended with "PHP_". If this directive is empty, most variables are alterable.

safe_mode_protected_env_vars = [LD_LIBRARY_PATH]

This option sets which environment variables users can't change in safe mode, even if safe_mode_allowed_env_vars is set permissively

disable_functions = [function1, function2...]

A welcome addition to PHP4 configuration and one perpetuated in PHP5 is the ability to disable selected functions for security reasons. Previously, this necessitated hand-editing the C code from which PHP was made. Filesystem, system, and network functions should probably be the first to go because allowing the capability to write files and alter the system over HTTP is never such a safe idea.

max_execution_time = 30

The function set_time_limit() won.t work in safe mode, so this is the main way to make a script time out in safe mode. In Windows, you have to abort based on maximum memory consumed rather than time. You can also use the Apache timeout setting to timeout if you use Apache, but that will apply to non-PHP files on the site too.

error_reporting = E_ALL & ~E_NOTICE

The default value is E_ALL & ~E_NOTICE, all errors except notices. Development servers should be set to at least the default; only production servers should even consider a lesser value

error_prepend_string = [""]

With its bookend, error_append_string, this setting allows you to make error messages a different color than other text, or what have you.

warn_plus_overloading = Off

This setting issues a warning if the + operator is used with strings, as in a form value.

variables_order = EGPCS

This configuration setting supersedes gpc_order. Both are now deprecated along with register_globals. It sets the order of the different variables: Environment, GET, POST, COOKIE, and SERVER (aka Built-in).You can change this order around. Variables will be overwritten successively in left-to-right order, with the rightmost one winning the hand every time. This means if you left the default setting and happened to use the same name for an environment variable, a POST variable, and a COOKIE variable, the COOKIE variable would own that name at the end of the process. In real life, this doesn't happen much.

register_globals = Off

This setting allows you to decide whether you wish to register EGPCS variables as global. This is now deprecated, and as of PHP4.2, this flag is set to Off by default. Use superglobal arrays instead. All the major code listings in this book use superglobal arrays.

gpc_order = GPC

This setting has been GPC Deprecated.

magic_quotes_gpc = On

This setting escapes quotes in incoming GET/POST/COOKIE data. If you use a lot of forms which possibly submit to themselves or other forms and display form values, you may need to set this directive to On or prepare to use addslashes() on string-type data.

magic_quotes_runtime = Off

This setting escapes quotes in incoming database and text strings. Remember that SQL adds slashes to single quotes and apostrophes when storing strings and does not strip them off when returning them. If this setting is Off, you will need to use stripslashes() when outputting any type of string data from a SQL database. If magic_quotes_sybase is set to On, this must be Off.

magic_quotes_sybase = Off

This setting escapes single quotes in incoming database and text strings with Sybase-style single quotes rather than backslashes. If magic_quotes_runtime is set to On, this must be Off.

auto-prepend-file = [path/to/file]

If a path is specified here, PHP must automatically include() it at the beginning of every PHP file. Include path restrictions do apply.

auto-append-file = [path/to/file]

If a path is specified here, PHP must automatically include() it at the end of every PHP file.unless you escape by using the exit() function. Include path restrictions do apply.

include_path = [DIR]

If you set this value, you will only be allowed to include or require files from these directories. The include directory is generally under your document root; this is mandatory if you.re running in safe mode. Set this to . in order to include files from the same directory your script is in. Multiple directories are separated by colons: .:/usr/local/apache/htdocs:/usr/local/lib.

doc_root = [DIR]

If you.re using Apache, you.ve already set a document root for this server or virtual host in httpd.conf. Set this value here if you.re using safe mode or if you want to enable PHP only on a portion of your site (for example, only in one subdirectory of your Web root).

file_uploads = [on/off]

Turn on this flag if you will upload files using PHP script.

upload_tmp_dir = [DIR]

Do not uncomment this line unless you understand the implications of HTTP uploads!

session.save-handler = files

Except in rare circumstances, you will not want to change this setting. So don't touch it.

ignore_user_abort = [On/Off]

This setting controls what happens if a site visitor clicks the browser.s Stop button. The default is On, which means that the script continues to run to completion or timeout. If the setting is changed to Off, the script will abort. This setting only works in module mode, not CGI.

mysql.default_host = hostname

The default server host to use when connecting to the database server if no other host is specified.

mysql.default_user = username

The default user name to use when connecting to the database server if no other name is specified.

mysql.default_password = password

The default password to use when connecting to the database server if no other password is specified.

7.Linux configuration while doing file hosting

8.svn?
Basically, it's an easy way to manage source code for projects like PCSX2. The SVN number is pretty much the build number (which is different from a release number like 0.9.6)
9.Why we go for oops? and disadvantages?
Major OOPs Concepts :-------------
* Objects
 * Classes
* Data Abstraction and Encapsulation
* Inheritance
* Polymorphism
OOPs has the following advantages over conventional approaches:
1-->OOP provides a clear modular structure for programs which makes it good for defining abstract datatypes where implementation details are hidden and the unit has a clearly defined interface.
 2-->OOP makes it easy to maintain and modify existing code as new objects can be created with small differences to existing ones.
3--> OOP provides a good framework for code libraries where supplied software components can be easily adapted and modified by the programmer. This is particularly useful for developing graphical user interfaces.

Objects

Objects are the basic run-time entities in an object-oriented system. Programming problem is analyzed in terms of objects and nature of communication between them. When a program is executed, objects interact with each other by sending messages. Different objects can also interact with each other without knowing the details of their data or code.

Classes

A class is a collection of objects of similar type. Once a class is defined, any number of objects can be created which belong to that class.

Data Abstraction and Encapsulation

Abstraction refers to the act of representing essential features without including the background details or explanations. Classes use the concept of abstraction and are defined as a list of abstract attributes. Storing data and functions in a single unit (class) is encapsulation. Data cannot be accessible to the outside world and only those functions which are stored in the class can access it.

Inheritance

Inheritance is the process by which objects can acquire the properties of objects of other class. In OOP, inheritance provides reusability, like, adding additional features to an existing class without modifying it. This is achieved by deriving a new class from the existing one. The new class will have combined features of both the classes.

Polymorphism

Polymorphism means the ability to take more than one form. An operation may exhibit different behaviors in different instances. The behavior depends on the data types used in the operation. Polymorphism is extensively used in implementing Inheritance.
·         Dis Advantages
1.As far as i know one of the major disadvantages of using oops is overhead in process of creating objects and performing other oops funtions.This is the real some systems in telecom domain still prefer C to C++ and java
2.Two other oops features that can get really hard to read are operator overloading (fortunately it's rarely used), and class properties that look like simple variable assignment but are really complex function calls
3. However, there is a slight cost in terms of efficiency. As objects are normally referenced by pointers, with memory allocated dynamically, there is a small space ovearhead to store the pointers, and a small speed overhead to find space on the heap (at run-time) to store the objects. For dynamic methods there is an additional small time penalty, as the method to choose is found at run time, by searching through the object hierarchy (using the class precedence list for the object). These days, these efficiency penalties seem to be of relatively little importance compared with the software engineering benefits.

No direct access to read/write class variables/attributes - may need to introduce getters and seeters which breaks incapsulation.
·         Inheritance can change the behavior of a method in a subclass
·         Objects have state. It can be hard to generate these states as we depend on the public interface.
·         Classes with loh cohesion can be hard to test as this could mean that the class does more than is specified.

10.Why we cannot implement multiple inheretence without interface?
The root of problems is most statically-typed languages don't support
virtual data fields. Think about it. You have virtual methods, how
come you don't have virtual data fields? (Virtual means overridable by subclasses.) The answer is performance. With non-overridable, fixed data fields, the advantage is that you can access the data members by fixed address offsets, eliminating the needs of vtables (virtual tables) or other indirect lookup mechanisms (e.g.: name dictionaries as in dynamically-typed languages), hence getting better performance and less memory usage.

Not having virtual data fields makes multiple inheritance very hairy. Suppose C inherits from A and B: (I hope you can see the ASCII diagram I am drawing)

A B
\ /
C

And suppose both A.x and B.x exist as actual data fields of A and B, respectively. Suppose C does not have actual data field x. When you do:

c = new C();
c.x = 1;

Which data field are you going to put the value to? A.x or B.x? You may say both. But what if later a method in B modifies only B.x? You get into a mess. You may say, OK, I need to have a single x, at C
level. Well, that's what virtual data field means. But sorry, the methods in A and B don't handle virtual data fields, they were pre-wired to use the address offsets of their own data members. So, the way out in C# and Java is simply to have single class inheritance and multiple interface inheritance. This way there is no confusion as which data field to assign the value to.
------------------
Initialization is another problem. The typical example is the diamond-shaped inheritance:

A
/ \
B C
\ /
D

If you have an object

d = new D()

You run the danger of using the constructor of A twice.
11.Php parellel processing/multi tasking?

1.     multi_curl
2.     One can use system command for the same
3.     Ideal scenario is, create a threading function in C language and compile/configure in PHP. Now that function will be the function of PHP.
4.     bq. Besides using curl for getting the content of other websites, it is also possible to use curl for multithreading in PHP. PHP has no native support for multithreading like Java. Each PHP request is a separate thread. There are some workarounds like using pcntl_fork, starting multiple commandline PHP processes using the exec command or even using ajax. Another possibility is using the Curl library.
5.     p. It’s pretty light on the WHY but it makes up for it with the HOW. If you like articles that are generously sprinkled with example code, you are going to love this one
Some time ago, I’ve wrote a small server in PHP. Nothing fancy. It would listen on a socket and when a new client would connect, the server would start a new thread and manage the client’s request. Since threading it’s not available in PHP, I’ve emulated the threads with child processes which are available in php. A thread object simply encapsulates a new process started with pnctl_fork() and emulates – to some extent – the behaviour of the java.lang.Thread class, the main difference being that in my implementation, you don’t extend the Thread class, you simply provide the name of a callback function in the constructor.
12.What is the major usage of scripting languages (js,jquery,ajax)?
Advantages: They allow you to create dynamic designs/programs that can adapt easily to user input.

Disadvantages: Not all scripting languages are supported by all systems. Choose your language carefully to ensure cross-platform compatibility as much as possible.

13.PHP library?
SPL(Standard PHP Library) is a collection of interfaces and classes that are meant to solve standard problems

Charting Library

You can create simple graph or chart using GD library on PHP, but to help you create more complex chart, then you’ll need this awesome library.
1.     pChart – a PHP class to build charts.
2.     Libchart – Simple PHP chart drawing library.
3.     JpGraph – Object-oriented graph creating library for PHP.
4.     Open Flash Chart – Flash based charting library.

RSS Parser Library

Parsing a RSS is not a fun thing to do, so you would better put this library and get everything done.
1.     MagpieRSS – RSS for PHP.
2.     SimplePie – Super-fast, easy-to-use, RSS and Atom feed parsing in PHP.

Thumbnail Generator

Just another way to create thumbnail.
1.     phpThumb – The PHP thumbnail creator.

Payment

Dealing with an e-commerce site? Need payment solution? Don’t worry. Let this library help you.
1.     PHP Payment Library – PHP Payment Library for Paypal, Authorize.net and 2Checkout (2CO)

OpenID

Just in case you need to implement OpenID to your project.
1.     PHP-OpenID – OpenID implementation in PHP.

Database Abstraction/ORM

Writing SQL Query isn’t really exciting. These library let you smile more.
1.     ADOdb – Database abstraction library for PHP.
2.     Doctrine – Object relational mapper (ORM) for PHP 5.2.3+ that sits on top of a powerful database abstraction layer (DBAL).
3.     Propel – Object-Relational Mapping framework for PHP5
4.     Outlet – an Open source object-to-relational mapping tool for PHP.

PDF Generator

1.     FPDF – PHP class which allows to generate PDF files with pure PHP.

Excel

Need to generate your report in Excel file. Well, you better have this library on your side.
1.     php-excel – Very simple library for generating excel documents from php on-the-fly.
2.     PHP Excel Reader – Parse and retrieve information from XLS files.

E-Mail

Don’t like PHP mail function? Put this library on your project, and you have more features when dealing with email.
1.     Swift Mailer – Free Feature-rich PHP Mailer.
2.     PHPMailer - Powerful email transport class with a big features and small footprint.

Unit Testing

For Test-driven development lover, these library will help you get your heart at home.
1.     SimpleTest – PHP unit test and web test framework.
2.     PHPUnit – Member of the xUnit family of testing frameworks and provides both a framework that makes the writing of tests easy as well as the functionality to easily run the tests and analyse their results.

14.How the php code executing
PHP -> Parsing-> opcode->executing->html output

15.web service? xml Usage?
What are Web Services?

  • Web services are application components
  • Web services communicate using open protocols
  • Web services are self-contained and self-describing
  • Web services can be discovered using UDDI
  • Web services can be used by other applications
  • XML is the basis for Web services

How Does it Work?

The basic Web services platform is XML + HTTP.
XML provides a language which can be used between different platforms and programming languages and still express complex messages and functions.
The HTTP protocol is the most used Internet protocol.
Web services platform elements:
  • SOAP (Simple Object Access Protocol)
  • UDDI (Universal Description, Discovery and Integration)
  • WSDL (Web Services Description Language)
Example:

Server:
<?php
// Pull in the NuSOAP code
require_once('nusoap.php');
// Create the server instance
$server = new soap_server;
// Register the method to expose
$server->register('hello');
// Define the method as a PHP function
function hello($name) {
    return 'Hello, ' . $name;
}
// Use the request to (try to) invoke the service
$HTTP_RAW_POST_DATA = isset($HTTP_RAW_POST_DATA) ? $HTTP_RAW_POST_DATA : '';
$server->service($HTTP_RAW_POST_DATA);
?>
Client
<?php
// Pull in the NuSOAP code
require_once('nusoap.php');
// Create the client instance
$client = new nusoap_client('http://localhost/xml-webservice/server.php');
// Check for an error
$err = $client->getError();
if ($err) {
    // Display the error
    echo '<h2>Constructor error</h2><pre>' . $err . '</pre>';
    // At this point, you know the call that follows will fail
}
// Call the SOAP method
$result = $client->call('hello', array('name' => 'Scott'));
// Check for a fault
if ($client->fault) {
    echo '<h2>Fault</h2><pre>';
    print_r($result);
    echo '</pre>';
} else {
    // Check for errors
    $err = $client->getError();
    if ($err) {
        // Display the error
        echo '<h2>Error</h2><pre>' . $err . '</pre>';
    } else {
        // Display the result
        echo '<h2>Result</h2><pre>';
        print_r($result);
    echo '</pre>';
    }
}
?>
<?php
// Display the request and response
echo '<h2>Request</h2>';
echo '<pre>' . htmlspecialchars($client->request, ENT_QUOTES) . '</pre>';
echo '<h2>Response</h2>';
echo '<pre>' . htmlspecialchars($client->response, ENT_QUOTES) . '</pre>';
?>
16.Difference between mysql and mysqli?
In relation to PHP programming language, MySQL is the old database driver, and MySQLi is the Improved driver. MySQLi takes advantage of the newer features of MySQL 5. Lifted verbatim from the php.net site:

- Object-oriented interface
- Support for Prepared Statements
- Support for Multiple Statements
- Support for Transactions
- Enhanced debugging capabilities
- Embedded server support
17.what is the usage of mysql engines?
the following engines, with a whole bunch of other information.
InnoDB   
MRG_MYISAM
BLACKHOLE 
CSV       
MEMORY
FEDERATED
ARCHIVE  
MyISAM    
As you can see they are a lot but we will focus on MyISAM and InnoDB here. Lets start with their limitations:-
MyISAM limitations
  • No Foriegn keys and cascading deletes and updates
  • No rollback abilities
  • No transactional integrity (ACID compliance)
  • Row limit of 4,284,867,296 rows
  • Maximum of 64 indexes per row
InnoDB Limitations
  • No full text indexing
  • Cannot be compressed for fast, read-only
MyISAM uses table level locking and this can be a great problem if your database INSERT/DELETE/UPDATE load is very high. If this is the problem then you should try converting it to INNODB. It manages non transactional tables. It has fast storage and retrieval, as well as full text searching capabilities. Its supported by every MySQL and comes as a default engine.
When to use MyISAM?
MyISAM is designed with the idea that your database is queried far more than its updated and as a result it performs very fast read operations. If your read to write(insert|update) ratio is less than 15% its better to use MyISAM.
When to use InnoDB?
InnoDB uses row level locking, has commit, rollback, and crash-recovery capabilities to protect user data. It supports transaction and fault tolerance.
1. A storage engine is a software which a DataBase management System uses to create, read, update and delete data from a database.
2. Storage engines are also called as DataBase Engines

Storage engines of MySQL

Engines
Description
MyISAM
Default storage engine, manages non transactional tables, provides high-speed storage and retrieval, supports full text searching.
MEMORY
Provides in-memory tables, formerly known as HEAP. It sores all data in RAM for faster access than storing data on disks. Useful for quick looks up of reference and other identical data.
MERGE
Groups more than one similar MyISAM tables to be treated as a single table, can handle non transactional tables, included by default.
InnoDB
Provides transaction-safe tables, supports FOREIGN KEY referential-integrity constraints. It supports commit, rollback, and crash-recovery capabilities to protect data. It also support row-level locking. It's "consistent nonlocking reads" increases performance when used in a multiuser environment. It stores data in clustered indexes which reduces I/O for queries based on primary keys.
BDB
Provides transaction-safe tables.
EXAMPLE
You can create tables with this engine, but can not store or fetch data. Purpose of this is to teach developers about how to write a new storage engine.
NDBCLUSTER
Used by MySQL Cluster to implement tables that are partitioned over many computers. Works on number of Unix platforms, works on Windows experimentally.
ARCHIVE
Used to store a large amount of data, does not support indexes.
CSV
Stores data in Comma Separated Value format in a text file.
BLACKHOLE
Accepts data to store but always returns empty.
FEDERATED
Added in MySQL 5.0.3. Stores data in a remote database.

18.what is the use of constraints?
Constraints are used to limit the type of data that can go into a table.
Constraints can be specified when a table is created (with the CREATE TABLE statement) or after the table is created (with the ALTER TABLE statement).
We will focus on the following constraints:
  • NOT NULL
  • UNIQUE
  • PRIMARY KEY
  • FOREIGN KEY
  • ENUM
  • SET
·         The next chapters will describe each constraint in detail.
An ENUM value must be one of those listed in the column definition, or the internal numeric equivalent thereof. The value cannot be the error value (that is, 0 or the empty string). For a column defined as ENUM('a','b','c'), values such as
'', 'd', or 'ax' are illegal and are rejected.
·         A SET value must be the empty string or a value consisting only of the values listed in the column definition separated by commas. For a column defined as SET('a','b','c'), values such as 'd' or 'a,b,c,d' are illegal and are rejected.

19.Mysql stored proceture? advantage?
Definition of stored procedure

A stored procedure is a segment of declarative SQL code, which is stored in the database catalog. A stored procedure can be invoked by a program, a trigger or even another stored procedure.
A stored procedure which calls itself is recursive stored procedure. Almost RDMBS supports recursive stored procedure but MySQL does not support it well. You should check your version of MySQL database before implementing recursive stored procedures.

Stored Procedures Advantages

  • Stored procedure increases performance of application. Once created, stored procedure is compiled and stored in the database catalog. It runs faster than uncompiled SQL commands which are sent from application.
  • Stored procedure reduces the traffic between application and database server because instead of sending multiple uncompiled lengthy SQL commands statements, the application only has to send the stored procedure's name and get the data back.
  • Stored procedure is reusable and transparent to any application which wants to use it. Stored procedure exposes the database interface to all applications so developers don't have to program the functions which are already supported in stored procedure in all external applications.
  • Stored procedure is secured. Database administrator can grant the access right to application which wants to access stored procedures in database catalog without granting any permission on the underlying database tables.

Stored Procedures Disadvantages

  • Stored procedures make the database server high load in both memory and processors. Instead of being focused on the storing and retrieving data, you could be asking the database server to perform a number of logical operations or a complex of business logic which is not the well designed in database server.
  • Stored procedure only contains declarative SQL so it is very difficult to write a procedure with complexity of business logic like other languages in application layer such as Java, C#, C++…
  • Stored procedure is difficult to debug. You cannot debug stored procedure in almost RDMBSs and in MySQL also. There are some workarounds on this problem but it still not easy enough to do so.
  • Store procedure is not easy to write and maintain. Writing and maintaining stored procedure is usually required specialized skill set that not all developers possess. This may introduced problems in both application development and maintain phase.
20.Mysql functions? advantages?
A function always returns a result, and can be called inside an SQL statement just like ordinary SQL functions. A function parameter is the equivalent of the IN procedure parameter, as functions use the RETURN keyword to determine what is passed back. Stored functions also have slightly more limitations in what SQL statements they can run than stored procedures.
21.How mysql queries are executing?
22.Indexing and it's types?
A database index is a data structure that improves the speed of operations in a table. Indexes can be created using one or more columns, providing the basis for both rapid random lookups and efficient ordering of access to records.
While creating index it should be considered that what are the columns which will be used to make SQL queries and create one or more indexes on those columns.
Practically, Indexes are also type of tables which keeps primary key or index field and a pointer to each record in to the actual table.
The users cannot see the indexes, they are just used to speed up queries and will be used by Database Search Engine to locate records very fast.
INSERT and UPDATE statements takes more time on tables having indexes where as SELECT statements become fast on those tables. The reason is that while doing insert or update, database need to inert or update index values as well.

Simple and Unique Index:

You can create a unique index on a table. A unique index means that two rows cannot have the same index value. Here is the syntax to create an Index on a table
CREATE UNIQUE INDEX index_name
ON table_name ( column1, column2,...);
You can use one or more columns to create an index. For example we can create an index on tutorials_tbl using tutorial_author
CREATE UNIQUE INDEX AUTHOR_INDEX
ON tutorials_tbl (tutorial_author)
You can creates a simple index on a table. Just omit UNIQUE keyword from the query to create simple index. Simple index allows duplicate values in a table.
If you want to index the values in a column in descending order, you can add the reserved word DESC after the column name:
mysql> CREATE UNIQUE INDEX AUTHOR_INDEX
ON tutorials_tbl (tutorial_author DESC)

ALTER command to add and drop INDEX:

There are four types of statements for adding indexes to a table:
·         ALTER TABLE tbl_name ADD PRIMARY KEY (column_list) : This statement adds a PRIMARY KEY, which means that indexed values must be unique and cannot be NULL.
·         ALTER TABLE tbl_name ADD UNIQUE index_name (column_list): This statement creates an index for which values must be unique (with the exception of NULL values, which may appear multiple times).
·         ALTER TABLE tbl_name ADD INDEX index_name (column_list): This adds an ordinary index in which any value may appear more than once.
·         ALTER TABLE tbl_name ADD FULLTEXT index_name (column_list): This creates a special FULLTEXT index that is used for text-searching purposes.
Here is the example to add index in an existing table.
mysql> ALTER TABLE testalter_tbl ADD INDEX (c);
You can drop any INDEX by using DROP clause along with ALTER command. Try out following example to drop above created index.
mysql> ALTER TABLE testalter_tbl DROP INDEX (c);
You can drop any INDEX by using DROP clause along with ALTER command. Try out following example to drop above created inde x.

ALTER Command to add and drop PRIMARY KEY:

You can add primary key as well in the same way. But make sure Primary Key works on columns which are NOT NULL.
Here is the example to add primary key in an existing table. This will make a column NOT NULL first and then add it as a primary key.
mysql> ALTER TABLE testalter_tbl MODIFY i INT NOT NULL;
mysql> ALTER TABLE testalter_tbl ADD PRIMARY KEY (i);
You can use ALTER command to drop a primary key as follows:
mysql> ALTER TABLE testalter_tbl DROP PRIMARY KEY;
To drop an index that is not a PRIMARY KEY, you must specify the index name.

Displaying INDEX Information:

You can use SHOW INDEX command to list out all the indexes associated with a table. Vertical-format output (specified by \G) often is useful with this statement, to avoid long line wraparound:
Try out following example:
mysql> SHOW INDEX FROM table_name\G
Indexing Types
Primary Key Indexes
Unique Key Indexes
Normal Indexes also known as "Non-Unique Indexes", "Ordinary Indexes", or "Indexes without constraints"
Full-Text Indexes
23.Transaction? how it's working and data's are takes place?
A transaction is a sequential group of database manipulation operations, which is performed as if it were one single work unit. In other words, a transaction will never be complete unless each individual operation within the group is successful. If any operation within the transaction fails, the entire transaction will fail.
Practically you will club many SQL queries into a group and you will execute all of them together as a part of a transaction.

Properties of Transactions:

Transactions have the following four standard properties, usually referred to by the acronym ACID:
·         Atomicity: ensures that all operations within the work unit are completed successfully; otherwise, the transaction is aborted at the point of failure, and previous operations are rolled back to their former state.
·         Consistency: ensures that the database properly changes states upon a successfully committed transaction.
·         Isolation: enables transactions to operate independently of and transparent to each other.
·         Durability: ensures that the result or effect of a committed transaction persists in case of a system failure.
In MySQL, transactions begin with the statement BEGIN WORK and end with either a COMMIT or a ROLLBACK statement. The SQL commands between the beginning and ending statements form the bulk of the transaction.

COMMIT and ROLLBACK:

These two keywords Commit and Rollback are mainly used for MySQL Transactions.
·         When a successful transaction is completed, the COMMIT command should be issued so that the changes to all involved tables will take effect.
·         If a failure occurs, a ROLLBACK command should be issued to return every table referenced in the transaction to its previous state.
You can control the behavior of a transaction by setting session variable called AUTOCOMMIT. If AUTOCOMMIT is set to 1 (the default), then each SQL statement (within a transaction or not) is considered a complete transaction, and committed by default when it finishes. When AUTOCOMMIT is set to 0, by issuing the SET AUTOCOMMIT=0 command, the subsequent series of statements acts like a transaction, and no activities are committed until an explicit COMMIT statement is issued.
You can execute these SQL commands in PHP by using mysql_query() function.

Generic Example on Transaction

This sequence of events is independent of the programming language used; the logical path can be created in whichever language you use to create your application.
You can execute these SQL commands in PHP by using mysql_query() function.
1.     Begin transaction by issuing SQL command BEGIN WORK
2.     Issue one or more SQL commands like SELECT, INSERT, UPDATE or DELETE
3.     Check if there is no error and everything is according to your requirement.
4.     If there is any error then issue ROLLBACK command otherwise issue a COMMIT command.

24.ORM?
Introduction

ORM (Object Relational mapping) is a technique in which Objects oriented languages i.e Objects are mapped directly to relational databases. This is a generic concept which can be applied to any object oriented language like C++, Java, PHP etc and any relational database like Oracle, Mysql etc.

Object Relational Mapping Frameworks

Generally if you are working in a big web application you will have the data stored in some relational database. For e.g. If you are using PHP to build web applications there is a good chance that you would be using MySql as your relational database. As the application gets large dealing in with SQL in your PHP code gets very messy.
 ORM frameworks are generally written in an object oriented programming language like PHP and map (or even generate) objects which directly map to relational databases.
 So if you have an ORM object of customer and want to save it in your database the code required to do that would be some what like the following if you use an ORM frame work
 $objCustomer = new Customer();
$objCustomer->name=”John”
$objCustomer->emaail=” john124@example.com”;
$objCustomer->save(); 
Some of the good Object Relational Mapping Frameworks in PHP
CakePHP
Doctrine
Propel
CoughPHP
Symphony

Advantages of using a PHP ORM framework.

Most PHP ORM frameworks generate code which is required for CRUD ( Create Read Update Delete ) operation on the database automatically . This helps in rapid development of the application as one requires to deal with only high level things of the application. The code for basic database functionalities is directly taken care by the PHP ORM framework

In relational database you have a type like int, text, blog etc associated to each field in the database. Sometimes we have to convert the type on the fly from get data or storing data in the database from PHP code. This all will be taken care by the PHP ORM framework which is used in the project.

As the PHP ORM frameworks are used by many people they are less likely to have security problems than hand written code specifically for your project. This protects your application from attacks like SQL injections etc.

By using ORM frameworks there is no mixing of SQL code with business layer code of your application. This makes the code much easier to maintain.

If during the lifecycle of the application the backend database needs to be changed then if a PHP ORM framework is will become comparatively much easier to perform a transition then if one was not using a ORM framework.



25. Cron tab-> only url or any other method is there?
Setting up cron jobs in Unix and Solaris
cron is a unix, solaris utility that allows tasks to be automatically run in the background at regular intervals by the cron daemon. These tasks are often termed as cron jobs in unix , solaris.  Crontab (CRON TABle) is a file which contains the schedule of cron entries to be run and at specified times.
This document covers following aspects of Unix cron jobs
1. Crontab Restrictions
2. Crontab Commands
3. Crontab file – syntax
4. Crontab Example
5. Crontab Environment
6. Disable Email
7. Generate log file for crontab activity
1. Crontab Restrictions
You can execute crontab if your name appears in the file /usr/lib/cron/cron.allow. If that file does not exist, you can use
crontab if your name does not appear in the file /usr/lib/cron/cron.deny.
If only cron.deny exists and is empty, all users can use crontab. If neither file exists, only the root user can use crontab. The allow/deny files consist of one user name per line.
2. Crontab Commands
export EDITOR=vi ;to specify a editor to open crontab file.
crontab -e    Edit your crontab file, or create one if it doesn’t already exist.
crontab -l      Display your crontab file.
crontab -r      Remove your crontab file.
crontab -v      Display the last time you edited your crontab file. (This option is only available on a few systems.)
3. Crontab file
Crontab syntax :
A crontab file has five fields for specifying day , date and time followed by the command to be run at that interval.
*     *       *           command to be executed
-     -     -   -    -
|     |     |   |    |
|     |     |   |    +----- day of week (0 - 6) (Sunday=0)
|     |     |   +------- month (1 - 12)
|     |     +--------- day of        month (1 - 31)
|     +----------- hour (0 - 23)
+------------- min (0 - 59)
* in the value field above means all legal values as in braces for that column.
The value column can have a * or a list of elements separated by commas. An element is either a number in the ranges shown above or two numbers in the range separated by a hyphen (meaning an inclusive range).
Notes
A. ) Repeat pattern like /2 for every 2 minutes or /10 for every 10 minutes is not supported by all operating systems. If you try to use it and crontab complains it is probably not supported.
B.) The specification of days can be made in two fields: month day and weekday. If both are specified in an entry, they are cumulative meaning both of the entries will get executed .
4. Crontab Example
A line in crontab file like below removes the tmp files from /home/someuser/tmp each day at 6:30 PM.
30     18     *     *     *         rm /home/someuser/tmp/*
Changing the parameter values as below will cause this command to run at different time schedule below :
min
hour
day/month
month
day/week
Execution time
30
0
1
1,6,12
*
– 00:30 Hrs  on 1st of Jan, June & Dec.

0
20
*
10
1-5
–8.00 PM every weekday (Mon-Fri) only in Oct.

0
0
1,10,15
*
*
– midnight on 1st ,10th & 15th of month

5,10
0
10
*
1
– At 12.05,12.10 every Monday & on 10th of every month
:
Note : If you inadvertently enter the crontab command with no argument(s), do not attempt to get out with Control-d. This removes all entries in your crontab file. Instead, exit with Control-c.
5. Crontab Environment
cron invokes the command from the user’s HOME directory with the shell, (/usr/bin/sh).
cron supplies a default environment for every shell, defining:
HOME=user’s-home-directory
LOGNAME=user’s-login-id
PATH=/usr/bin:/usr/sbin:.
SHELL=/usr/bin/sh
Users who desire to have their .profile executed must explicitly do so in the crontab entry or in a script called by the entry.
6. Disable Email
By default cron jobs sends a email to the user account executing the cronjob. If this is not needed put the following command At the end of the cron job line .
>/dev/null 2>&1
7. Generate log file
To collect the cron execution execution log in a file :
30 18 * * * rm /home/someuser/tmp/* > /home/someuser/cronlogs/clean_tmp_dir.log

26. What are the ways we can call the php function
call_user_funcCall the callback given by the first parameter
call_user_func('increment'$a);
call_user_func_array('increment', array(&$a)); // You can use this instead before PHP 5.3
27. Apache config?
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} –d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]
php_flag display_errors 1