Skip to content

Commit ee5ee84

Browse files
Rewrite Persistent connections page to remove personalization and bad grammar (#5502)
1 parent c78af13 commit ee5ee84

1 file changed

Lines changed: 57 additions & 60 deletions

File tree

features/persistent-connections.xml

Lines changed: 57 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -7,64 +7,64 @@
77
<title>What are Persistent Connections?</title>
88
<simpara>
99
Persistent connections are links that do not close when the
10-
execution of your script ends. When a persistent connection is
11-
requested, PHP checks if there's already an identical persistent
12-
connection (that remained open from earlier) - and if it exists, it
13-
uses it. If it does not exist, it creates the link. An 'identical'
14-
connection is a connection that was opened to the same host, with
15-
the same username and the same password (where applicable).
10+
execution of the script ends. When a persistent connection is
11+
requested, PHP checks whether an identical persistent
12+
connection (that remained open from earlier) already exists; if one does,
13+
it is reused, and if not, a new link is created. An 'identical'
14+
connection is one opened to the same host with
15+
the same username and password (where applicable).
1616
</simpara>
1717
<simpara>
18-
There's no method of requesting a specific connection, or guaranteeing
19-
whether you get an existing connection or a brand new one (if all existing
20-
connections are in use, or the request is being served by a different worker,
21-
which has a separate pool of connections).
18+
There is no way to request a specific connection, or to guarantee
19+
whether the returned connection will be an existing one or a brand new
20+
one (if all existing connections are in use, or the request is being
21+
served by a different worker, which has a separate pool of connections).
2222
</simpara>
2323
<simpara>
24-
This means that you cannot use PHP's persistent connections to, for example:
24+
PHP's persistent connections therefore cannot be used to, for example:
2525
</simpara>
2626
<simplelist>
2727
<member>assign a specific database session to a specific web user</member>
2828
<member>create a large transaction across multiple requests</member>
2929
<member>initiate a query on one request and collect the results on another</member>
3030
</simplelist>
3131
<simpara>
32-
Persistent connections do not give you <emphasis>any</emphasis>
33-
functionality that wasn't possible with non-persistent connections.
32+
Persistent connections do not provide <emphasis>any</emphasis>
33+
functionality that was not possible with non-persistent connections.
3434
</simpara>
3535
</simplesect>
3636

3737
<simplesect xml:id="persistent-connections.web">
3838
<title>Web Requests</title>
3939
<simpara>
40-
There are two ways in which your web server can utilize PHP to generate
40+
There are two ways in which a web server can utilize PHP to generate
4141
web pages:
4242
</simpara>
4343
<simpara>
4444
The first method is to use PHP as a CGI "wrapper". When run this
4545
way, an instance of the PHP interpreter is created and destroyed
46-
for every page request (for a PHP page) to your web server.
46+
for every page request (for a PHP page) to the web server.
4747
Because it is destroyed after every request, any resources that it
4848
acquires (such as a link to an SQL database server) are closed when
49-
it is destroyed. In this case, you do not gain anything from trying
50-
to use persistent connections - they simply don't persist.
49+
it is destroyed. In this case, there is nothing to be gained from
50+
using persistent connections - they simply do not persist.
5151
</simpara>
5252
<simpara>
5353
The second, and most popular, method is to run PHP-FPM, or PHP as a module
54-
in a multiprocess web server, which currently only includes Apache.
54+
in a multiprocess web server (currently only Apache).
5555
These setups typically have one process (the parent) which
56-
coordinates a set of processes (its children) who actually do the
56+
coordinates a set of processes (its children) that actually do the
5757
work of serving up web pages. When a request comes in from a
5858
client, it is handed off to one of the children that is not already
5959
serving another client. This means that when the same client makes
6060
a second request to the server, it may be served by a different
61-
child process than the first time. When opening a persistent connection,
62-
every following page requesting SQL services can reuse the same
63-
established connection to the SQL server.
61+
child process than the first time. Once a persistent connection has been
62+
opened, any subsequent page served by the same child process can reuse the
63+
already established connection to the SQL server.
6464
</simpara>
6565
<note>
6666
<para>
67-
You can check which method your web requests use by checking the value of
67+
The method in use can be checked by looking at the value of
6868
"Server API" in the output of <function>phpinfo</function> or the value of
6969
<constant>PHP_SAPI</constant>, run from a web request.
7070
</para>
@@ -82,59 +82,56 @@
8282
As command-line PHP uses a new process for each script, persistent
8383
connections are not shared between command-line scripts, so there is no
8484
value in using them in transient scripts such as crons or commands.
85-
However, they may be useful if, for example, you're writing a long-running
86-
application server that serves many requests or tasks and each may need
87-
their own database connection.
85+
However, they may be useful, for example, in a long-running application
86+
server that serves many requests or tasks, each of which may need its
87+
own database connection.
8888
</simpara>
8989
</simplesect>
9090

9191
<simplesect xml:id="persistent-connections.why">
9292
<title>Why Use Them?</title>
9393
<simpara>
94-
Persistent connections are good if the overhead to create a link to your
95-
SQL server is high. Whether or not this overhead is really high depends
96-
on many factors. Like, what kind of database it is, whether or not
97-
it sits on the same computer on which your web server sits, how
98-
loaded the machine the SQL server sits on is and so forth. The
99-
bottom line is that if that connection overhead is high, persistent
100-
connections help you considerably. They cause the child process to
101-
simply connect only once for its entire lifespan, instead of every
102-
time it processes a page that requires connecting to the SQL
103-
server. This means that for every child that opened a persistent
104-
connection will have its own open persistent connection to the
105-
server. For example, if you had 20 different child processes that
106-
ran a script that made a persistent connection to your SQL server,
107-
you'd have 20 different connections to the SQL server, one from
108-
each child.
94+
Persistent connections are beneficial when the overhead of creating a link
95+
to an SQL server is high. Whether this overhead is significant depends on
96+
many factors, such as the type of database, whether it resides on the same
97+
machine as the web server, and how loaded that machine is. When the
98+
connection overhead is high, persistent connections can help considerably:
99+
each child process connects only once for its entire lifespan, rather than
100+
every time it processes a page that requires a connection to the SQL
101+
server. This means every child that opens a persistent connection will
102+
maintain its own connection to the server. For example, if 20 different
103+
child processes each run a script that makes a persistent connection to
104+
the SQL server, there will be 20 separate connections to that server, one
105+
from each child.
109106
</simpara>
110107
</simplesect>
111108

112109
<simplesect xml:id="persistent-connections.drawbacks.conn-limits">
113110
<title>Potential Drawbacks: Connection Limits</title>
114111
<simpara>
115-
Note, however, that this can have some drawbacks if you are using a
112+
Note, however, that this can have drawbacks when using a
116113
database with connection limits that are exceeded by persistent
117-
child connections. If your database has a limit of 16 simultaneous
118-
connections, and in the course of a busy server session, 17 child
119-
threads attempt to connect, one will not be able to. If there are
120-
bugs in your scripts which do not allow the connections to shut
121-
down (such as infinite loops), the database with only 16 connections
114+
child connections. If the database has a limit of 16 simultaneous
115+
connections, and during a busy server session 17 child
116+
processes attempt to connect, one of them will fail. If there are
117+
bugs in the scripts that prevent connections from shutting
118+
down (such as infinite loops), a database with only 16 connections
122119
may be rapidly swamped.
123120
</simpara>
124121
<simpara>
125122
Persistent connections will usually increase the number of connections open
126-
at any given time because idle workers will still hold the connections for
127-
the previous requests they served. If a large number of workers is spun up to
128-
handle an influx of requests, the connections they opened will remain until
129-
the worker is killed or the database server closes the connection.
123+
at any given time, because idle workers still hold on to the connections they
124+
opened for previous requests. If a large number of workers are spun up to
125+
handle a spike in traffic, the connections they opened will remain until
126+
the worker is terminated or the database server closes the connection.
130127
</simpara>
131128
<simpara>
132129
Ensure that the maximum number of connections allowed by the database server
133130
is greater than the maximum number of web request workers (plus any other
134131
usage such as crons or administrative connections).
135132
</simpara>
136133
<simpara>
137-
Check your database documentation for information on handling abandoned or
134+
Check the database documentation for information on handling abandoned or
138135
idle connections (timeouts). Long timeouts may significantly increase the
139136
number of persistent connections open at any one time.
140137
</simpara>
@@ -171,20 +168,20 @@
171168
to recreate the same table.
172169
</simpara>
173170
<simpara>
174-
You can implement cleanup using class destructors or
175-
<function>register_shutdown_function</function>. You may also want to
176-
consider dedicated connection pooling proxies that include this as part of
177-
their functionality.
171+
Cleanup can be implemented using class destructors or
172+
<function>register_shutdown_function</function>. Dedicated connection
173+
pooling proxies that include this as part of their functionality may
174+
also be considered.
178175
</simpara>
179176
</simplesect>
180177

181178
<simplesect xml:id="persistent-connections.final-words">
182179
<title>Final Words</title>
183180
<simpara>
184-
Given their behavior and potential drawbacks described above, you should not
185-
use persistent connections without careful consideration. They should not be
186-
used without implementing additional changes to your application and careful
187-
configuration of your database server and web server and/or PHP-FPM.
181+
Given their behavior and potential drawbacks described above, persistent
182+
connections should not be used without careful consideration. They should
183+
not be used without implementing additional changes to the application and
184+
careful configuration of the database server and web server and/or PHP-FPM.
188185
</simpara>
189186
<simpara>
190187
Consider alternative solutions such as investigating and fixing the causes of

0 commit comments

Comments
 (0)