Wednesday, 17 February 2016

PHP interview questions



-What is PHP?
Ans. PHP is a recursive acronym for "PHP: Hypertext Preprocessor". PHP is a server side scripting language that is embedded in HTML. It is used to manage dynamic content, databases, session tracking, even build entire e-commerce sites.

-In how many ways you can embed PHP code in an HTML page?
Ans. All PHP code must be included inside one of the three special markup tags ate are recognised by the PHP Parser.
<?php PHP code goes here ?>
<?    PHP code goes here ?>
<script language="php"> PHP code goes here </script>
Most common tag is the <?php...?>

-Is PHP a case sensitive language?
Ans. Yes!

-types of PHP variables?
Ans. 
   Integers − are whole numbers, without a decimal point, like 4195. 
   Doubles − are floating-point numbers, like 3.14159 or 49.1. 
   Booleans − have only two possible values either true or false. 
   NULL − is a special type that only has one value: NULL. 
   Strings − are sequences of characters, like 'PHP supports string operations.' 
   Arrays − are named and indexed collections of other values. 
   Objects − are instances of programmer-defined classes, which can package up both other kinds of values and functions that are specific to the class. 
   Resources − are special variables that hold references to resources external to PHP (such as database connections).

-What is NULL?
Ans. NULL is a special type that only has one value: NULL. To give a variable the NULL value, simply assign it like this −$my_var = NULL;
The special constant NULL is capitalized by convention, but actually it is case insensitive; you could just as well have typed −$my_var = null;
A variable that has been assigned NULL has the following properties:It evaluates to FALSE in a Boolean context.It returns FALSE when tested with IsSet() function.

-What is the purpose of _CLASS_ constant?
Ans. _CLASS_ − The class name. (Added in PHP 4.3.0) As of PHP 5 this constant returns the class name as it was declared (case-sensitive). In PHP 4 its value is always lowercased.

-How will you find the length of a string in PHP?
Ans. <?php echo strlen("Hello world!"); ?>
 
-What is the difference between include() Function and require() Function?
Ans. If there is any problem in loading a file then the require() function generates a fatal error and halt the execution of the script whereas include() function generates a warning but the script will continue execution.
 
-How will you read a file in php?
Ans. Once a file is opened using fopen() function it can be read with a function called fread(). This function requires two arguments. These must be the file pointer and the length of the file expressed in bytes.
 
-How will you set cookies using PHP?
Ans. PHP provided setcookie() function to set a cookie. This function requires upto six arguments and should be called before <html> tag. For each cookie this function has to be called separately.
setcookie(name, value, expire, path, domain, security);
 
-What does PEAR stands for?
Ans. PEAR means “PHP Extension and Application Repository”. it extends PHP and provides a higher level of programming for web developers.
 
-How do you execute a PHP script from the command line?
Ans. ust use the PHP command line interface (CLI) and specify the file name of the script to be executed as follows: “php script.php”
 
-What is the difference between Session and Cookie?
Ans. The main difference between sessions and cookies is that sessions are stored on the server, and cookies are stored on the user’s computers in the text file format. Cookies can not hold multiple variables,But Session can hold multiple variables.We can set expiry for a cookie,The session only remains active as long as the browser is open.Users do not have access to the data you stored in Session,Since it is stored in the server.Session is mainly used for login/logout purpose while cookies using for user activity tracking.
 
-What is the use of explode() function ?
Ans. Syntax : array explode ( string $delimiter , string $string [, int $limit ] ); 

This function breaks a string into an array. Each of the array elements is a substring of string formed by splitting it on boundaries formed by the string delimiter.
 
-What is the difference between explode() and split() functions?
Ans. Split function splits string into array by regular expression. Explode splits a string into array by string.
 
-What is the use of mysql_real_escape_string() function?
Ans. It is used to escapes special characters in a string for use in an SQL statement.
 
-What is the difference between mysql_fetch_array() and mysql_fetch_assoc() ?
Ans. 
mysql_fetch_assoc function Fetch a result row as an associative array, While 
mysql_fetch_array() fetches an associative array, a numeric array, or both
 
-How do you define a constant?
Ans. Using define() directive, like define ("MYCONSTANT",150)
 
-How send email using php?
Ans. mail($to,$subject,$message,$headers);
 
-What are the encryption techniques in PHP ?
Ans. 
MD5 PHP implements the MD5 hash algorithm using the md5 function,
eg : $encrypted_text = md5 ($msg); 
mcrypt_encrypt :- string mcrypt_encrypt ( string $cipher , string $key , string $data , string $mode [, string $iv ] ); 
Encrypts plaintext with given parameters 
 
-How to delete a file from the system?
Ans. Unlink() deletes the given file from the file system.
 
-What is the use of the function htmlentities?
Ans. htmlentities Convert all applicable characters to HTML entities This function is identical to htmlspecialchars() in all ways, except with htmlentities(), all characters which have HTML character entity equivalents are translated into these entities.

Friday, 12 February 2016

Magento site speed optimization with htaccess

Now a days its most important to speed up your web site for getting more customer to visit it. If its taking more time to load then may be you could lost that customer.

Here i list few points regarding speed optimization of Magento web site with "htaccess" file :

=> Use Apache mod_expires and be sure to set how long files should be cached. You could use the below code for your Apache virtualhost config
<ifmodule mod_expires.c>
ExpiresActive On
ExpiresDefault "access plus 1 month"
ExpiresByType image/jpg "access 1 year"
ExpiresByType image/jpeg "access 1 year"
ExpiresByType image/gif "access 1 year"
ExpiresByType image/png "access 1 year"
ExpiresByType text/css "access 1 month"
ExpiresByType text/html "access 1 month"
ExpiresByType application/pdf "access 1 month"
ExpiresByType text/x-javascript "access 1 month"
ExpiresByType application/x-shockwave-flash "access 1 month"
ExpiresByType application/javascript "access plus 1 year"
ExpiresByType image/x-icon "access 1 year"
</ifmodule>

=> Adjust memory limit what ever you want :
## adjust memory limit
# php_value memory_limit 64M
php_value memory_limit 256M
php_value max_execution_time 18000


=> Enable Gzip Compression with htaccess as below :
<ifModule mod_gzip.c>
mod_gzip_on Yes
mod_gzip_dechunk Yes
mod_gzip_item_include file \.(html?|txt|css|js|php|pl|asp|html)$
mod_gzip_item_include handler ^cgi-script$
mod_gzip_item_include mime ^text/.*
mod_gzip_item_include mime ^application/x-javascript.*
mod_gzip_item_exclude mime ^image/.*
mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.*
</ifModule>


=> Use Apache mod_headers as below, add it in htaccess :
<IfModule mod_headers.c>
# YEAR
<FilesMatch "\.(ico|gif|jpg|jpeg|png|flv|pdf)$">
Header set Cache-Control "max-age=29030400"
</FilesMatch>
# WEEK
<FilesMatch "\.(js|css|swf)$">
Header set Cache-Control "max-age=604800"
</FilesMatch>
# 45 MIN
<FilesMatch "\.(html|htm|txt)$">
Header set Cache-Control "max-age=86400"
</FilesMatch>
</IfModule>

=> Add mod_deflate as below :
<IfModule mod_deflate.c>
############################################
## enable apache served files compression
## http://developer.yahoo.com/performance/rules.html#gzip

AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE text/javascript
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript
# Insert filter on all content
SetOutputFilter DEFLATE
# Insert filter on selected content types only
#AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css text/javascript
# Netscape 4.x has some problems...
BrowserMatch ^Mozilla/4 gzip-only-text/html
# Netscape 4.06-4.08 have some more problems
BrowserMatch ^Mozilla/4\.0[678] no-gzip
# MSIE masquerades as Netscape, but it is fine
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
# Don't compress images
SetEnvIfNoCase Request_URI \.(?:gif|jpe?g|png)$ no-gzip dont-vary
# Make sure proxies don't deliver the wrong content
Header append Vary User-Agent env=!dont-vary
</IfModule>

Saturday, 6 February 2016

Magento Interview Question - Answers

1. What is Magento?

Ans. Magento is a rich-featured eCommerce platform built on open-source technology that provides online merchants with unprecedented flexibility and control over the look, content and functionality of their eCommerce store. Magentos intuitive administration interface features powerful marketing, search engine optimization and catalog-management tools to give merchants the power to create sites that are tailored to their unique business needs. Designed to be completely scalable and backed by Variens support network, Magento offers companies the ultimate eCommerce solution.



2. What architecture is used by Magento?

Ans. MVC which means Model-View-Controller.



3. How much Magento product Types?

Ans.
- Simple products
A Magento simple product is the most used product type for Magento webshops. This is because it's the most general product type of them all. A Magento simple product should be used for a single item without any specific selectable variations. Think about a coffee cup, a chandelier, a table or whatever.


- Grouped products
A Magento grouped product should be used for a combination of Magento simple products. Think about a coffee cup that is sold together with a saucer, a silver spoon, a breakfast plate or whatever. You can't define a specific price for a Magento grouped product but you can define a discount amount.


- Configurable products
A Magento configurable product should be used for a single item with specific selectable variations. Think about a coffee cup obtainable in different colours and sizes, a woman's bag obtainable in different materials, a light boll obtainable in different watts or whatever. Each selectable variation can have its own additional costs.


- Virtual products
A Magento virtual product should be used for a virtual (not touchable) item. Think about an insurance, a reservation, an extra product guarantee or whatever. A virtual product does not allow selecting a shipping method at checkout simply because there's nothing to ship.


- Bundle products
A Magento bundle product should be used for a bundle of simple (or virtual) products which are not to be sold separately. Think about a laptop where the customer can choose various items such as hard disk, processor, internal memory or whatever. Each of these items are simple (or virtual) products but can only be sold within the bundle product.


- Downloadable products
A Magento downloadable product should be used for online software items. Think about an MP3 file, a PowerPoint presentation, a Magento extension or whatever. A downloadable product does not allow selecting a shipping method at checkout simply because there's nothing to ship.



4. What are the different features of Magento?

Ans.
- User Management
- Customer Management
- Product Management
- Order Management
- Payment Management
- Site Management
- Search engine optimization
- International Support



5. What is Magento module structure?

Ans.
- app/ 1) code 2) etc
- code => local => Namespache => modulename => Block
- controllers
- etc
- Helper
- Model
- sql



6. How we can enhance the Magento performance?

Ans.
- Disable the Magento log
- Disable any un-used modules (i.e, mage_poll)
- Magento Caching ( Enable Cache for good result)
- Enable Gzip compression
- USE Gzip Components
- Optimize your images
- Optimize your Server
- Use a Content Delivery Network (CDN)
- Put Stylesheets at Top (Add CSS Files in head tag)
- Put Scripts at the Bottom (Add Js files in footer)
- Avoid CSS Expressions



7. what is the difference between Mage::getModel() and Mage::getSingletone() in Magento?

Ans.
- Mage::getModel(): It always creates a new object
- Mage::getSingleton(): It always look for an existing object and if not then creates a new object



8. What technology used by Magento?

Ans.
Magento uses PHP as a web server scripting language and the MySQL Database. The data model is based on the Entity-attribute-value model that stores data objects in tree structures, thus allowing a change to a data structure without changing the database definition.



9. How to create magento custom module?

Ans.
Steps to create custom magento module:
Namespace : Uts
Module Name : Utsmodule
- Create directory Utsmodule in app/code/local/Uts
- Create Block, controllers, etc, Utsmodule directories.( Create controller, block and module file as required.)
- Create module configuration file (app/code/local/Uts/Utsmodule/etc/config.xml).
- Create xml file (app/etc/modules/Uts_Utsmodule.xml)to enable/disable module and tell magento system from which code pool that module will be taken.



10. How to include CMS block in template file(.phtml)?

Ans.
Access block's content from .phtml template file by :
echo $this->getLayout()->createBlock('cms/block')->setBlockId('static_block_id')->toHTML();


about new GraphQL freature in Magento2

GraphQL: GraphQL is a data query language developed internally by Facebook in 2012 before being publicly released in 2015. Magento impleme...