php-doc-en/reference/mongo/mongoclient/close.xml
2015-11-19 13:46:44 +00:00

175 lines
4.8 KiB
XML

<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->
<refentry xml:id="mongoclient.close" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
<refnamediv>
<refname>MongoClient::close</refname>
<refpurpose>Closes this connection</refpurpose>
</refnamediv>
<refsynopsisdiv role="soft-deprecation-notice">
<sidebar>
&mongo.noalternative.method.note;
</sidebar>
</refsynopsisdiv>
<refsect1 role="description">
&reftitle.description;
<methodsynopsis>
<modifier>public</modifier> <type>bool</type><methodname>MongoClient::close</methodname>
<methodparam choice="opt"><type>boolean|string</type><parameter>connection</parameter></methodparam>
</methodsynopsis>
<para>
The <function>MongoClient::close</function> method forcefully closes a
connection to the database, even if persistent connections are being used.
You should <emphasis>never</emphasis> have to do this under normal
circumstances.
</para>
<para>
</para>
</refsect1>
<refsect1 role="parameters">
&reftitle.parameters;
<para>
<variablelist>
<varlistentry>
<term>
<parameter>connection</parameter>
</term>
<listitem>
<para>
If connection is not given, or &false; then connection that would be
selected for writes would be closed. In a single-node configuration,
that is then the whole connection, but if you are connected to a
replica set, close() will <emphasis>only</emphasis> close the
connection to the primary server.
</para>
<para>
If connection is &true; then all connections as known by the connection
manager will be closed. This can include connections that are not
referenced in the connection string used to create the object that
you are calling close on.
</para>
<para>
If connection is a string argument, then it will only close the
connection identified by this hash. Hashes are identifiers for a
connection and can be obtained by calling
<function>MongoClient::getConnections</function>.
</para>
</listitem>
</varlistentry>
</variablelist>
</para>
</refsect1>
<refsect1 role="returnvalues">
&reftitle.returnvalues;
<para>
Returns if the connection was successfully closed.
</para>
</refsect1>
<refsect1 role="examples">
&reftitle.examples;
<example>
<title><function>MongoClient::close</function> example</title>
<para>This example demonstrates how to selectively close all connections
for secondaries only.</para>
<programlisting role="php">
<![CDATA[
<?php
// Connect to a replicaset
$a = new MongoClient("mongodb://whisky:13000/?replicaset=seta");
$connections = $a->getConnections();
foreach ( $connections as $con )
{
// Loop over all the connections, and when the type is "SECONDARY"
// we close the connection
if ( $con['connection']['connection_type_desc'] == "SECONDARY" )
{
echo "Closing '{$con['hash']}': ";
$closed = $a->close( $con['hash'] );
echo $closed ? "ok" : "failed", "\n";
}
}
?>
]]>
</programlisting>
&example.outputs;
<screen>
<![CDATA[
Closing 'whisky:13001;X;4948': ok
]]>
</screen>
</example>
</refsect1>
<refsect1 role="changelog">
&reftitle.changelog;
<para>
<informaltable>
<tgroup cols="2">
<thead>
<row>
<entry>&Version;</entry>
<entry>&Description;</entry>
</row>
</thead>
<tbody>
<row>
<entry>1.3.0</entry>
<entry>
<para>
The <parameter>connection</parameter> parameter to this function was
added in 1.3.0. Before that, only the write connection would be
closed by this method.
</para>
</entry>
</row>
<row>
<entry>1.2.0</entry>
<entry>
<para>
Before version 1.2.0 the driver would not use persistent connections
by default, and all connections would be closed as soon as a MongoDB
connection went out if scope. Since version 1.2.0 this is no longer
the case and it is a bad idea to call close as you might end up
overloading the server with connections under high load.
</para>
</entry>
</row>
</tbody>
</tgroup>
</informaltable>
</para>
</refsect1>
<refsect1 role="seealso">
&reftitle.seealso;
<simplelist>
<member><function>MongoClient::getConnections</function></member>
</simplelist>
</refsect1>
</refentry>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
sgml-parent-document:nil
sgml-default-dtd-file:"~/.phpdoc/manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
vim600: syn=xml fen fdm=syntax fdl=2 si
vim: et tw=78 syn=sgml
vi: ts=1 sw=1
-->