update construct options

git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@312772 c90b9560-bf6c-de11-be94-00142212c4b1
This commit is contained in:
Kristina Chodorow 2011-07-01 15:45:12 +00:00
parent 5dc9ad2fb7
commit 377da021f6

View file

@ -16,12 +16,12 @@
</methodsynopsis>
<para>
If no parameters are passed, this connects to "localhost:27017" (or whatever
was specified in php.ini for
<link linkend="ini.mongo.default-host">mongo.default_host</link> and
was specified in php.ini for
<link linkend="ini.mongo.default-host">mongo.default_host</link> and
<link linkend="ini.mongo.default-port">mongo.default_port</link>).
</para>
<para>
<parameter>server</parameter> should have the form:
<parameter>server</parameter> should have the form:
<programlisting>
<![CDATA[
mongodb://[username:password@]host1[:port1][,host2[:port2:],...]/db
@ -29,24 +29,24 @@ mongodb://[username:password@]host1[:port1][,host2[:port2:],...]/db
</programlisting>
</para>
<para>
The connection string always starts with <literal>mongodb://</literal>, to
indicate it is a connection string in this form.
The connection string always starts with <literal>mongodb://</literal>, to
indicate it is a connection string in this form.
</para>
<para>If <literal>username</literal> and <literal>password</literal>
are specified, the constructor will attempt to authenticate the connection
are specified, the constructor will attempt to authenticate the connection
with the database before returning. Username and password are optional
and must be followed by an <literal>@</literal>, if specified.
and must be followed by an <literal>@</literal>, if specified.
</para>
<para>
At least one host must be given (port optional, always defaulting to 27017)
and as many hosts as desired may be connected to. Host names are
comma-separated and the constructor will return successfully if it connected
to at least one host. If it could not connect to any of the hosts, it will
At least one host must be given (port optional, always defaulting to 27017)
and as many hosts as desired may be connected to. Host names are
comma-separated and the constructor will return successfully if it connected
to at least one host. If it could not connect to any of the hosts, it will
throw a <classname>MongoConnectionException</classname>.
</para>
<para>
Finally, if you specified a username and password, you may specify a database
to authenticate with. If <literal>db</literal> is not specified, "admin"
to authenticate with. If <literal>db</literal> is not specified, "admin"
will be used.
</para>
</refsect1>
@ -79,25 +79,10 @@ mongodb://[username:password@]host1[:port1][,host2[:port2:],...]/db
<literal>"connect"</literal>
</para>
<para>
If the constructor should connect before returning. Default is
If the constructor should connect before returning. Default is
&true;.
</para>
</listitem>
<listitem>
<para>
<literal>"persist"</literal>
</para>
<para>
If the connection should be persistent. If set, the connection will
be persistent. The string representation of the value is used as an
id for the connection, so two instances of
<classname>Mongo</classname> that are initialized with
<literal>array("persist" => "foobar")</literal> will share the same
database connection, whereas an instance initialized with
<literal>array("persist" => "barbaz")</literal> will use a different
database connection.
</para>
</listitem>
<listitem>
<para>
<literal>"timeout"</literal>
@ -112,7 +97,7 @@ mongodb://[username:password@]host1[:port1][,host2[:port2:],...]/db
<literal>"replicaSet"</literal>
</para>
<para>
If this hosts listed are seeds of a replica set. If they are, the
The name of the replica set to connect to. If this is given, the
master will be determined by using the <literal>ismaster</literal>
database command on the seeds, so the driver may end up connecting to
a server that was not even listed. See the replica set example below
@ -155,7 +140,7 @@ mongodb://[username:password@]host1[:port1][,host2[:port2:],...]/db
<refsect1 role="errors">
&reftitle.errors;
<para>
Throws <classname>MongoConnectionException</classname> if it tries and fails
Throws <classname>MongoConnectionException</classname> if it tries and fails
to connect to the database for all hostnames given. It will also throw a
<classname>MongoConnnectionException</classname> if an invalid username or
password is given. See <classname>MongoConnectionException</classname>
@ -176,6 +161,36 @@ mongodb://[username:password@]host1[:port1][,host2[:port2:],...]/db
</thead>
<tbody>
<row>
<entry>1.2.0</entry>
<entry>
<para>
Removed the persist option, as all connections are now persistent. It
can still be used, but it doesn't affect anything.
<variablelist>
<varlistentry>
<term>
<parameter>"persist"</parameter>
</term>
<listitem>
<para>
If the connection should be persistent. If set, the connection will
be persistent. The string representation of the value is used as an
id for the connection, so two instances of
<classname>Mongo</classname> that are initialized with
<literal>array("persist" => "foobar")</literal> will share the same
database connection, whereas an instance initialized with
<literal>array("persist" => "barbaz")</literal> will use a different
database connection.
</para>
</listitem>
</varlistentry>
</variablelist>
</para>
<para>
The "replicaSet" parameter now takes a string, not a boolean (although
boolean is still accepted).
</para>
</entry>
<entry>1.0.2</entry>
<entry>
Changed constructor to take an array of options. Pre-1.0.2, the
@ -197,7 +212,7 @@ mongodb://[username:password@]host1[:port1][,host2[:port2:],...]/db
</term>
<listitem>
<para>
Optional boolean parameter specifying if the constructor should
Optional boolean parameter specifying if the constructor should
connect to the database before returning. Defaults to &true;.
</para>
</listitem>
@ -234,7 +249,7 @@ mongodb://[username:password@]host1[:port1][,host2[:port2:],...]/db
<row>
<entry>1.2.0</entry>
<entry>
Added the <literal>username</literal> and <literal>password</literal>
Added the <literal>username</literal> and <literal>password</literal>
options.
</entry>
</row>
@ -258,17 +273,17 @@ mongodb://[username:password@]host1[:port1][,host2[:port2:],...]/db
<?php
// pass a comma-separated list of server names to the constructor
$m1 = new Mongo("mongodb://sf2.example.com,ny1.example.com", array("replicaSet" => true));
$m1 = new Mongo("mongodb://sf2.example.com,ny1.example.com", array("replicaSet" => "myReplSet"));
// you only need to pass a single seed, the driver will derive the full list and
// find the master from this seed
$m2 = new Mongo("mongodb://ny1.example.com", array("replicaSet" => true));
$m2 = new Mongo("mongodb://ny1.example.com", array("replicaSet" => "myReplSet"));
?>
]]>
</programlisting>
<para>
If the current master fails, the driver will figure out which secondary
If the current master fails, the driver will figure out which secondary
server became the new master and automatically start using that connection.
Automatic failover will not work correctly if <literal>replicaSet</literal>
is not specified.
@ -280,20 +295,20 @@ $m2 = new Mongo("mongodb://ny1.example.com", array("replicaSet" => true));
<para>
If you include seeds from two separate replica sets, behavior is undefined.
</para>
<para>See the
<link xlink:href="&url.mongodb.dochub.rs;">core documentation</link> on
<para>See the
<link xlink:href="&url.mongodb.dochub.rs;">core documentation</link> on
replica sets for more information.
</para>
</example>
<example>
<title>Connecting to a domain socket</title>
<para>
In version 1.0.9+, you can use a UNIX domain socket to connect to an
In version 1.0.9+, you can use a UNIX domain socket to connect to an
instance of MongoDB running locally. This should be slightly faster than
using a network connection.
</para>
<para>
In version 1.5.0, the MongoDB server automatically opens a socket at
In version 1.5.0, the MongoDB server automatically opens a socket at
/tmp/mongodb-&lt;port&gt;.sock. You can connect to this by specifying the
path in your connection string:
</para>
@ -317,43 +332,6 @@ $m = new Mongo("mongodb:///tmp/mongodb-20000.sock");
// try to connect to the domain socket, fall back to localhost connection
$m = new MongoDB("mongodb:///tmp/mongodb-27017.sock,localhost:27017");
?>
]]>
</programlisting>
</example>
<example>
<title><function>Mongo::__construct</function> persistent connection example</title>
<para>
A persistent connection will last for more than one request (usually...
milage may vary depending on server). It can save significant time to
reuse connections, as creating a connection is a time-intensive process.
</para>
<para>
A persistent connection is identified by the server string and an id
string.
</para>
<programlisting role="php">
<![CDATA[
<?php
// creates a persistent connection
$m1 = new Mongo("mongodb://localhost", array("persist" => ""));
// uses the same connection as $m1
$m2 = new Mongo("mongodb://localhost", array("persist" => ""));
// creates a new connection
$m3 = new Mongo("mongodb://127.0.0.1", array("persist" => ""));
// creates a new connection
$m4 = new Mongo("mongodb://127.0.0.1:27017", array("persist" => ""));
// creates a new connection
$m5 = new Mongo("mongodb://localhost", array("persist" => "foo"));
// uses the $m5 connection
$m6 = new Mongo("mongodb://localhost", array("persist" => "foo"));
?>
]]>
</programlisting>
@ -361,7 +339,7 @@ $m6 = new Mongo("mongodb://localhost", array("persist" => "foo"));
<example>
<title><function>Mongo::__construct</function> authentication example</title>
<para>
A user must exist in the admin database before attempting to use
A user must exist in the admin database before attempting to use
authentication. You can create one with the Mongo shell by running:
</para>
<programlisting>
@ -412,4 +390,4 @@ End:
vim600: syn=xml fen fdm=syntax fdl=2 si
vim: et tw=78 syn=sgml
vi: ts=1 sw=1
-->
-->