If we would like to pass values througn a form or an URL then we need to encode and to decode them using htmlspecialchars() and urlencode().
Monthly Archives: June 2015
How comparison of objects is done in PHP5?
When using the comparison operator (==), object variables are compared in a simple manner, namely: Two object instances are equal if they have the same attributes and values, and are instances of the same class.
When using the identity operator (===), object variables are identical if and only if they refer to the same instance of the same class.
Redis
Redis is a data structure server. It is open-source, networked, in-memory, and stores keys with optional durability.
Redis is an open source, BSD licensed, advanced key-value cache and store. It is often referred to as a data structure server since keys can contain strings, hashes, lists, sets, sorted sets, bitmaps and hyperloglogs.
Varnish
Varnish is an HTTP accelerator designed for content-heavy dynamic web sites as well as heavily consumed APIs.
Varnish Cache is a web application accelerator also known as a caching HTTP reverse proxy. You install it in front of any server that speaks HTTP and configure it to cache the contents. Varnish Cache is really, really fast. It typically speeds up delivery with a factor of 300 – 1000x, depending on your architecture.
Varnish stores data in virtual memory and leaves the task of deciding what is stored in memory and what gets paged out to disk to the operating system. This helps avoid the situation where the operating system starts caching data while it is moved to disk by the application.
Furthermore, Varnish is heavily threaded, with each client connection being handled by a separate worker thread. When the configured limit on the number of active worker threads is reached, incoming connections are placed in an overflow queue; when this queue reaches its configured limit incoming connections will be rejected.
What is the difference between $argv and $argc PHP ?
$argc — The number of arguments passed to script
$argv — Array of arguments passed to script
To pass the information into the script from outside, help can be taken from the PHP CLI (Command line interface) method. Suppose addition of two numbers has to be passed to PHP then it can be passed like this on the command line:
Write a statement to show the joining of multiple comparisons in PHP?
PHP allows multiple comparisons to be grouped together to determine the condition of the statement. It can be done by using the following syntax:
comparison1 and|or|xor comparison2 and|or|xor comparison3 and|or|xor.
The operators that are used with comparisons are as follows:
1. and: result in positive when both comparisons are true.
2. or: result in positive when one of the comparisons or both of the comparisons are true.
3. xor: result in positive when one of the comparisons is true but not both of the comparisons.
What is the use of $_Server and $_Env?
$_SERVER and $_ENV arrays contain different information. The information depends on the server and operating system being used. Most of the information can be seen of an array for a particular server and operating system.
What is the use of super-global arrays in PHP?
Super global arrays are the built in arrays that can be used anywhere. They are also called as auto-global as they can be used inside a function as well. The arrays with the longs names such as $HTTP_SERVER_VARS, must be made global before they can be used in an array. This $HTTP_SERVER_VARS check your php.ini setting for long arrays.
What are the different components used in PHP for formatting?
The components that are used in PHP for formatting are as follows:
1. %: it tells the start of the formatting instruction.
2. Padding character (pad): is used to fill out the string when the value to be formatted is smaller than the width assigned. Pad can be a space, a 0, or any character preceded by a single quote (‘).
3. -: A symbol meaning to left-justify the characters. If this is not included, the characters are right-justified.
4. width: The number of characters to use for the value. If the value doesn’t fill the width, the padding character is used to pad the value. For example, if the width is 5, the padding character is 0, and the value is 1, the output is 00001.
5. dec: The number of decimal places to use for a number. This value is preceded by a decimal point.
6. type: The type of value. Use s(string) for string, f (float) for numbers that you want to format with decimal places.
How can we increase the execution time of a php script?
By the use of void set_time_limit(int seconds)
Set the number of seconds a script is allowed to run. If this is reached, the script returns a fatal error. The default limit is 30 seconds or, if it exists, the max_execution_time value defined in the php.ini. If seconds is set to zero, no time limit is imposed.
When called, set_time_limit() restarts the timeout counter from zero. In other words, if the timeout is the default 30 seconds, and 25 seconds into script execution a call such as set_time_limit(20) is made, the script will run for a total of 45 seconds before timing out.