How do you increase the max number of concurrent connections in Apache?

By default, apache2 is configured to support 150 concurrent connections. This forces all parallel requests beyond that limit to wait. Especially if, for example, active sync clients maintain a permanent connection for push events to arrive.

This is an example configuration to provide 8000 concurrent connections. Please ensure that your apache is using the mpm_worker. This allows us to serve lots of concurrent connections by using less RAM than with mpm_prefork as we are going to start much less processes. (mpm_event, which is stated to be stable by Apache nowadays, shows problems in load tests, with connection timeouts.)

<IfModule mpm_worker_module>
    ServerLimit              250
    StartServers              10
    MinSpareThreads           75
    MaxSpareThreads          250 
    ThreadLimit               64
    ThreadsPerChild           32
    MaxRequestWorkers       8000
    MaxConnectionsPerChild 10000

Note: MaxRequestWorkers was previously named MaxClients and MaxConnectionsPerChild was previously named MaxRequestsPerChild. If you are using old (pre 2.4) version of Apache you might need to use the old names.

The short explanation of the parameters:

ServerLimit Declares the maximum number of running apache processes. If you change this value you have to restart the daemon.
StartServers The number of processes to start initially when starting the apache daemon.
MinSpareThreads/MaxSpareThreads This regulates how many threads may stay idle without being killed. Apache regulates this on its own very well with default values.
ThreadsPerChild How many threads can be created per process. Can be changed during a reload.
ThreadLimit ThreadsPerChild can be configured as high as this value during runtime. If you change this value you have to restart the daemon.
MaxRequestWorkers This declares how many concurrent connections we provide. Divided by ThreadsPerChild you get the suitable ServerLimit value. Maybe less than ServerLimit * ThreadsPerChild to reserve some resources that can be engaged during runtime with increasing MaxRequestWorkers and reloading the configuration.
MaxConnectionsPerChild Defines the number of Connections that a process can handle during its lifetime (keep-alives are counted once). After that, it will be killed. This can be used to prevent possible apache memory leaks. If set to 0 the lifetime is infinite.



Build Currency Converter with PHP

function currencyConverter($from_Currency,$to_Currency,$amount) {
$from_Currency = urlencode($from_Currency);
$to_Currency = urlencode($to_Currency);
$encode_amount = 1;
$get = file_get_contents($encode_amount&from=$from_Currency&to=$to_Currency&#8221;);
$get = explode(“<span class=bld>”,$get);
$get = explode(“</span>”,$get[1]);
$rate= preg_replace(“/[^0-9\.]/”, null, $get[0]);
$converted_amount = $amount*$rate;
$data = array( ‘rate’ => $rate, ‘converted_amount’ =>$converted_amount, ‘from_Currency’ =>strtoupper($from_Currency), ‘to_Currency’ => strtoupper($to_Currency));
echo json_encode( $data );

Best Practice 4 – Code should be written to be reviewed

While writing your software code, keep in mind that someone is going to review your code and you will have to face criticism about one or more of the following points but not limited to:

  • Bad coding
  • Not the following standard
  • Not keeping performance in mind
  • History, Indentation, Comments are not appropriate.
  • Readability is poor
  • Open files are not closed
  • Allocated memory has not been released
  • Too many global variables.
  • Too much hard coding.
  • Poor error handling.
  • No modularity.
  • Repeated code.

Keep all the above-mentioned points in your mind while coding and stop them before they jump in your source code. Once you are done with your coding, go for a self-review atleast once. I’m sure, a self-review would help you in removing 90% problems yourself.

Once you are completely done with your coding and self review, request your peer for a code review. I would strongly recommend to accept review comments happily and should be thankful to your code reviewers about the comments. Same time, it is never good to criticize any source code written by someone else. If you never did it, try it once and check the coder’s expression.

It is special chacter(s) which have special meaning in Regular Expression.

For Example:
*, ., /, \, ? and ^.

Sr Meta character Desctiption
1 [ ] Match any character within [phc]
Means find “p” OR “h” OR “c”
2 Range
a-z means a to z(a,b,c, … z)

0-0 means 0 to 9 (0,1,2,3,4,5,6,7,8,9)

A-Z means A to Z(A,B,C,D ….. Z)

3 ^ Caret It means start with a character

For example: ^ab (start with “a”)

Inside the bracket if have opposite meaning.

For example: [^a](must not start with “a”)

4 $ End with character

For Example

Abc$ means end with “c”

5 . The . (period) means any character(s) in this position,
For example, ph. will find php, php-tutorial and php-tutorial-php but not aphp because it has no following character
6 ? Matches the preceding character 0 or 1 times only.

For example:

colou?r will find both color (0 times) and colour (1 time).

7 * Matches the preceding character 0 or more times.
For example:

tre* will find tree (2 times) and tread (1 time) and trough (0 times).

8 + Matches the previous character 1 or more times.
For example:

tre+ will find tree (2 times) and tread (1 time) but NOT trough (0 times).

9 {n} Preceding character, or character range, n times exactly.
For example:

find a local phone number we could use [0-9]{3}-[0-9]{4} which would find any number of the form 723-4567 OR 132-3234 OR 214-3433.

10 () To group a character.

For Example:
(php), will find the “php” only.

11 | Vertical bar used for OR

(a|c) find either “a” OR “c”

12 \d any character in the range 0 – 9
13 \D Any character not in between 0-9
14 \s Whitespace or tab
15 \S Not whitespace or tab
16 \w Alphanumeric characters (a-z, 0-9, A-Z)
17 \W Not alphanumeric character (a-z, 0-9, A-Z)