Tuesday, 31 March 2020

Push Notification

Basically, push notification is used for Android and windows but all are use different push notification server.
    Push notification is a message that pop-up on the mobile device. App publisher can send push notification them at any time. User don't have to be in app or using the device to receive them. Push notification looks like SMS, text message and mobile alert but they only reach users who have install there app.
  Push notification is a way to speak directly to a user they don't caught in the spam filter. They can also remind users to use an app whether app is open or not.

History In Short

1. June 2009:- Apple launches Apple push notification service (APNS) the first push service.
2. May 2010:- Google released it services Cloud to Device Messaging (C2DM).
3. May 2013:- Google introduced " Rich Notification" it can contain image as well as action button.

Thursday, 28 December 2017

Difference between PHP5 and PHP7

1. 1st difference is name i.e PHP7. The stable release PHP5x version is PHP5.6 After some dispute the development team decided they would omit the PHP6 name for next major release.PHP 6 already existed in the past as an experimental project but never reached the production phase.

2. PHP7 receives a brand new version of the Zend engine coming under the code name PHP#NG(Next Generation). PHP5 uses Zend Engine II.

3. The biggest change in PHP7 is speed.By using PHP 7 not only your code will be executed faster but you will also need fewer servers to serve the same amount of users.

4. Error handling. To say the least, handling fatal and catchable fatal errors have never been an easy task for PHP coders. The new Engine Exceptions will allow you to replace this kind of errors with exceptions. If the exception is not caught, PHP will continue to return the same fatal errors as it does in the current 5.X series.

5. 64-bit windows system support. PHP 7 will change this as it introduces consistent 64-bit support which means both native 64-bit integers and large files will be supported.5.X series don’t yet provide 64-bit integer or large file support, so until now x64 builds have been considered experimental.

6. New Spaceship(<=>) and Null Coalescing Operators(??)
    The Spaceship operator runs under the official name of Combined Comparison Operator.
     The spaceship operator returns 0 if both operands are equal, 1 if the left is greater, and -1 if the right is greater. It’s also called a three-way comparison operator.
    The Null Coalescing operator uses when you want to check if something exists and return a default value, in case it doesn’t. The coalesce operator returns the result of its first operand if it exists and is not null, and the second operand in any other cases.
 ex. PHP5 :- $userid=isset($_GET['id'])?$_GET['id']:'null';
     PHP7:- $userid=$_GET['id'] ?? 'null';

7. Enables Accurate Type Declarations
   The new PHP 7 enables developers to enhance the quality of their code with the help of return type declarations.PHP 7 introduces 4 new type declarations for scalar types: int, float, string and bool

8.  Adds Anonymous Classes
     The syntax is the same as what we are used to in traditional PHP classes, only the name is missing. If anonymous classes are used well, they can speed up coding as well execution time.

Tuesday, 26 December 2017

What is .htaccess

  In simple word we can say .htaccess is a configuration file for application which is running on Apache Web Server. .htaccess file is detected and executed by the Apache Web Server. This can be used to enable/disable additional functionality and feature offered by Apache web Server.
Some uses explain below shortly
Redirects
:-
     redirects is use to when you moved your web site content to new location it is help's user to redirect old link to new link
 
Password protection :-
    This is used for protected your directory from unauthorized users. you can give user name and password for loading site or directory.
 
Deny Visitors by IP address :-
    This is extremely useful for blocking unwanted visitors, or to only allow the web site owner access to certain sections of the web site.
 
Preventing access to your PHP includes files :-
    If you have a directory containing PHP includes, that you do not wish to be accessed directly from the browser, there is a way of disabling the directory using Mod_Rewrite.

URL rewriting :-
      This is useful for removing index.php, extension from url.

Saturday, 14 January 2017

Tips to optimize php script for better performance

1. Use PHP native functions :
         As much as possible try to use native PHP functions rather than writing your own functions to achieve the objective.
2. Use single quotes:
        Using single quotes is faster than using double quotes. If you are going to keep only the string inside it avoiding any variables.
3. Use === :
        Use '===' inserted of '==' as the former strictly checks for a closed range which makes it faster.
4. Use appropriate str function :
        str_replace is faster than preg_replace but strstr is faster than str_replace.
5. Calculate only once :
        calculate and assign the value to the variable it that value is getting used numerous time rather than calculating it again and again where it is being used.
eg. for($i=0;$i<count($array); $i++)
better
$len=count($array);
for($i=0;i<$len;$i++)
6. Pass reference to function :
        pass reference to the function if it is not affected your logic.A function manipulation the reference is faster than those manipulating the value been passed as here one more copy of the value is getting created.
7. Created classes when it's required :
        Don't create classes and methods until and unless its really needed. used and reused as well.
8. Disable debugging messages :
        File operations are expensive so if you have written lot of custom functions to log errors and warning during your development process make sure you remove them before you push the code to production.
9. Use caching techniques :
        use cache to reduce the load of database operations as well as the script compilation. mem cache for reducing database load and APC for opcode caching and intermediate code optimization.
10. Close the connection :
           Get into the habit to unset the variables and close database connection in your PHP code it save memory.
11. Reduce number of hits to database:
           Try to reduce the number of hits to the database. make queries aggregate so that you call the database less number of times.
12. Frequently used switch cases :
           Keep most frequently used switch case on the top.
13. Use method in derived classes:
            Method in derive class is faster than base class.
14. Use JSON :
          use JSON insated of XML while working with web services as therer are native PHP function like json_encode() and json_decode() which are very fast.
15. Use isset :
          Use isset where every possible insted of using count(), strlen(),sizeof() to check out greater then 0.

Wednesday, 27 July 2016

Webservice



What is a web service?

In simple word web services is a collection of standards or protocols for exchanging information between two devices or applications. Web service is language independent way of communication. We just look bellow figure to more clear our concept.
web services
In above figure you can see java can communicate to other languages like .net, PHP and vice versa by using web services i.e. web services has no language limitation.
Types of Web Services
There are mainly two types of web services.
  1. SOAP web services.
  2. RESTful web services.
SOAP Web Services :-
SOAP stands for Simple Object Access Protocol. It is a XML-based protocol for accessing web services.
SOAP is a W3C recommendation for communication between two applications.
It is platform independent and language independent. By using SOAP, you will be able to interact with other programming language applications.
Advantages of Soap Web Services
WS Security: SOAP defines its own security known as WS Security.
Language and Platform independent: SOAP web services can be written in any programming language and executed in any platform.


Disadvantages of Soap Web Services
Slow: SOAP uses XML format that must be parsed to be read. It defines many standards that must be followed while developing the SOAP applications. So it is slow and consumes more bandwidth and resource.
WSDL dependent: SOAP uses WSDL and doesn't have any other mechanism to discover the service.
Web Service Components
  1. SOAP
  2. WSDL
  3. UDDI
SOAP: SOAP is an acronym for Simple Object Access Protocol.
WSDL: WSDL is an acronym for Web Services Description Language. WSDL is pronounced as wiz-dull.
WSDL is a xml document containing information about web services such as method name, method parameter and how to access it.
WSDL is a part of UDDI. It acts as a interface between web service applications.
UDDI: UDDI is an acronym for Universal Description, Discovery and Integration.
UDDI is a XML based framework for describing, discovering and integrating web services.
UDDI is a directory of web service interfaces described by WSDL, containing information about web services.

RESTful Web Services :-
REST stands for REpresentational State Transfer.
REST is an architectural style not a protocol.
Advantages of RESTful Web Services
Fast: RESTful Web Services are fast because there is no strict specification like SOAP. It consumes less bandwidth and resource.
Language and Platform independent: RESTful web services can be written in any programming language and executed in any platform.
Can use SOAP: RESTful web services can use SOAP web services as the implementation.
Permits different data format: RESTful web service permits different data format such as Plain Text, HTML, XML and JSON

Monday, 15 February 2016

Simple PHP mail Function

PHP mail Function

$to      = $email_id;
$subject = "";
$message = "Your mail Body Content. you also use here HTML Tags for better performence. ";
$headers = 'From: xyz@domainname.com' . "\r\n" .
    'Reply-To: xyz@domainname.com' . "\r\n" .
    'X-Mailer: PHP/' . phpversion();
$headers.= "MIME-Version: 1.0" . "\r\n";
$headers.= "Content-type:text/html;charset=UTF-8" . "\r\n";

$test=mail($to, $subject, $message, $headers);

Monday, 11 January 2016

PHP Magic Methods

PHP Magic Methods


1.      __construct()  :- This method is called when someone create the object of class. Constructor is use to load default variable or methods which is call default when page is load. Constructor also inherit like any other methods.
2.      __destruct()  :-  This magic method is called when object of your class is unset. It gets run when the object is destroyed, either expressly by us or when we're not using it any more and PHP cleans it up for us. The destructor lets us close up any external resources that were being used by the object.
3.       __get()  :-  it makes properties which actually don't exist appear as if they do. This method called when your object attempt to read property or variable of the class which is inaccessible or unavailable.
4.     __set()   :- This method called when object of your class attempts to set value of the property which is really inaccessible or unavailable in your class.
5.     __isset()   :- This magic methods trigger when isset() function is applied on any property of the class which is in accessible or unavailable.
6.       __unset()  :-  __unset is something opposite of isset method. This method triggers when unset() function called on inaccessible or unavailable property of the class.
7.       __sleep()   :-  this methods trigger when you are going to serialize your class object. When the object is serialised and then unserialised then these types of references are useless since the target may no longer be present or valid.
8.       __wakeup()  :- this is exactly opposite of sleep method and allows you to alter the behaviour of the unserialisation of the object.  
9.       __tostring()   :-  This method executes when you are using echo on your object. Definitely saving the best until last, the __toString method is a very handy addition to our toolkit.

Thursday, 1 October 2015

MVC Architecture In PHP

MVC Architecture


mvc

Model
The Model is the name given to the permanent storage of the data used in the overall design. It must allow access for the data to be viewed, or collected and written to, and is the bridge between the View component and the Controller component in the overall pattern.
One important aspect of the Model is that it’s technically “blind” – by this I mean the model has no connection or knowledge of what happens to the data when it is passed to the View or Controller components. It neither calls nor seeks a response from the other parts; its sole purpose is to process data into its permanent storage or seek and prepare data to be passed along to the other parts.
The Model's job is to represent the problem domain, maintain state, and provide methods for accessing and mutating the state of the application. The Model layer is typically broken down into several different layers:
  • Service layer - this layer provides cohesive, high-level logic for related parts of an application. This layer is invoked directly by the Controller and View helpers.
  • Data Access layer - (ex. Data Gateway, Data Access Object) this layer provides access to the persistence layer. This layer is only ever invoked by Service objects. Objects in the data access layer do not know about each other.
  • Value Objects layer - this layer provides simple, data-oriented representations of "leaf" nodes in your model hierarchy.

View
The View is where data, requested from the Model, is viewed and its final output is determined. Traditionally in web apps built using MVC, the View is the part of the system where the HTML is generated and displayed. The View also ignites reactions from the user, who then goes on to interact with the Controller. The basic example of this is a button generated by a View, which a user clicks and triggers an action in the Controller.
The View's job is to translate data into a visual rendering for response to the Client (ie. web browser or other consumer). The data will be supplied primarily by the Controller; however, the View may also have a helper that can retrieve data that is associated with the rendering and not necessarily with the current request

Controller
The final component of the triad is the Controller. Its job is to handle data that the user inputs or submits, and update the Model accordingly. The Controller’s life blood is the user; without user interactions, the Controller has no purpose. It is the only part of the pattern the user should be interacting with.
The Controller can be summed up simply as a collector of information, which then passes it on to the Model to be organized for storage, and does not contain any logic other than that needed to collect the input. The Controller is also only connected to a single View and to a single Model, making it a one way data flow system, with handshakes and signoffs at each point of data exchange.
It’s important to remember the Controller is only given tasks to perform when the user interacts with the View first, and that each Controller function is a trigger, set off by the user’s interaction with the View.
The Controller's job is to translate incoming requests into outgoing responses. In order to do this, the controller must take request data and pass it into the Service layer. The service layer then returns data that the Controller injects into a View for rendering. This view might be HTML for a standard web request; or, it might be something like JSON (JavaScript Object Notation) for a RESTful API request.


Saturday, 18 July 2015

JSON Introduction

JSON - JavaScript Object Notation

               JSON is a lightweight text-based open standard data-interchange format. It is human readable. JSON is derived from a subset of JavaScript programming language. It is entirely language independent and can be used with most of the modern programming languages.
Key Points:

1.    There are four basic data types strings, numbers, booleans and null.
2. Objects are wrapped within ‘{’ and ‘}’. It is list of label – value pair.
3. Array are enclosed by ‘[’ and ‘]’. It is list of values.
4. Both object and array can be nested.
with the reference for more

json structure
 W3resources
Advantages of JSON:
1. Faster -:  JSON syntax is very easy to use. Which provide us a easy parsing of the data and faster execution of the data.
2. Portable -: It has wide range of supported browser compatibility with the operating systems so doesn’t require much effort to make it all browser compatible. JSON is portable because parsers and writers are available for many, many languages. It is the best way to transmit complex structures like arrays and objects, and have it still be compatible with multiple languages.
3. Server Parsing -: JSON server side parsing is strong point that indicates us to use the JSON on server side.
4. Tool for sharing data -: JSON is the best tool for the sharing data of any size even audio, video etc. This is because JSON stores the data in the arrays so data transfer makes easier. For this reason, JSON is a superior file format for web APIs and for web development.
5. Structure -: JSON provides structure because the data you transmit with it can have consistent formatting. This is instead of transmitting back plain-text (i.e. unformatted) data, like comma-separated or delimited data.
6. API -: API is the most widely used area where JSON is used for data exchange. Specially, web applications those have a social face, it has become obvious now that they have an API, so that developers can consume the huge amount of data collected by the app and then can create derivative apps.