added safe options

git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@296280 c90b9560-bf6c-de11-be94-00142212c4b1
This commit is contained in:
Kristina Chodorow 2010-03-16 15:15:54 +00:00
parent e1694ecb31
commit 13d9a87041
11 changed files with 364 additions and 21 deletions

View file

@ -5,6 +5,12 @@
<title>Mongo</title>
<titleabbrev>Mongo</titleabbrev>
<preface>
<para>
This extension allows you to connect to MongoDB through PHP.
</para>
</preface>
&reference.mongo.manual;
&reference.mongo.core;
&reference.mongo.types;

View file

@ -108,4 +108,61 @@ $m = new Mongo("mongodb://localhost:27017,localhost:27018");
</para>
</section>
<section>
<title>Persistent Connections</title>
<para>
Creating new connection to the database is very slow. To minimize the number
of connections that you need to make, you can use persistent connections. A
persistent connection is saved by PHP, so you can use the same connection for
multiple requests.
</para>
<para>
For example, this simple program connects to the database 1000 times:
</para>
<programlisting role="php">
<![CDATA[
<?php
for ($i=0; $i<1000; $i++) {
$m = new Mongo();
}
?>
]]>
</programlisting>
<para>
It takes approximately 18 seconds to execute. If we change it to use a
persistent connection:
</para>
<programlisting role="php">
<![CDATA[
<?php
for ($i=0; $i<1000; $i++) {
$m = new Mongo("localhost:27017", array("persist" => "x"));
}
?>
]]>
</programlisting>
<para>
...it takes less than .02 seconds to execute, as it only makes one database
connection.
</para>
<para>
Persistent connections need an identifier string (which is "x" in the above
example) to uniquely identify them. For a persistent connection to be used,
the hostname, port, persist string, and username and password (if given) must
match an existing persistent connection. Otherwise, a new connection will be
created with this identifying information.
</para>
</section>
</section>

View file

@ -10,8 +10,9 @@
<refsect1 role="description">
&reftitle.description;
<methodsynopsis>
<modifier>public</modifier> <type>boolean</type><methodname>MongoCollection::batchInsert</methodname>
<modifier>public</modifier> <type>mixed</type><methodname>MongoCollection::batchInsert</methodname>
<methodparam><type>array</type><parameter>a</parameter></methodparam>
<methodparam choice="opt"><type>array</type><parameter>options</parameter><initializer>array()</initializer></methodparam>
</methodsynopsis>
</refsect1>
@ -29,6 +30,26 @@
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>
<parameter>options</parameter>
</term>
<listitem>
<para>
Options for the inserts.
<itemizedlist>
<listitem>
<para>
<literal>"safe"</literal>
</para>
<para>
Check that the inserts succeeded.
</para>
</listitem>
</itemizedlist>
</para>
</listitem>
</varlistentry>
</variablelist>
</para>
</refsect1>
@ -36,7 +57,41 @@
<refsect1 role="returnvalues">
&reftitle.returnvalues;
<para>
Returns if the arrays were saved.
If "safe" is set, returns an associative array with the status of the inserts
("ok") and any error that may have occured ("err"). Otherwise, returns
&true; if the batch insert was successfully sent, &false; otherwise.
</para>
</refsect1>
<refsect1 role="errors">
&reftitle.errors;
<para>
Throws <classname>MongoCursorException</classname> if the "safe" option is
set and the insert fails.
</para>
</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.0.5</entry>
<entry>
Added "options" parameter.
</entry>
</row>
</tbody>
</tgroup>
</informaltable>
</para>
</refsect1>

View file

@ -12,7 +12,7 @@
<methodsynopsis>
<modifier>public</modifier> <type>mixed</type><methodname>MongoCollection::insert</methodname>
<methodparam><type>array</type><parameter>a</parameter></methodparam>
<methodparam choice="opt"><type>boolean</type><parameter>safe</parameter><initializer>false</initializer></methodparam>
<methodparam choice="opt"><type>array</type><parameter>options</parameter><initializer>array()</initializer></methodparam>
</methodsynopsis>
</refsect1>
@ -32,14 +32,24 @@
</varlistentry>
<varlistentry>
<term>
<parameter>safe</parameter>
<parameter>options</parameter>
</term>
<listitem>
<para>
If the database should check that the insert was successful.
Options for the insert.
<itemizedlist>
<listitem>
<para>
<literal>"safe"</literal>
</para>
<para>
Check that the insert succeeded.
</para>
</listitem>
</itemizedlist>
</para>
</listitem>
</varlistentry>
</varlistentry>
</variablelist>
</para>
</refsect1>
@ -56,7 +66,32 @@
<refsect1 role="errors">
&reftitle.errors;
<para>
Throws MongoCursorException if <parameter>safe</parameter> is set and the insert fails. (Version 1.0.1+)
Throws MongoCursorException if the "safe" option is set and the insert fails. (Version 1.0.1+)
</para>
</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.0.5</entry>
<entry>
Changed second parameter to an array of options. Pre-1.0.5, the
second parameter was a boolean indicating the "safe" option.
</entry>
</row>
</tbody>
</tgroup>
</informaltable>
</para>
</refsect1>

View file

@ -10,9 +10,9 @@
<refsect1 role="description">
&reftitle.description;
<methodsynopsis>
<modifier>public</modifier> <type>boolean</type><methodname>MongoCollection::remove</methodname>
<modifier>public</modifier> <type>mixed</type><methodname>MongoCollection::remove</methodname>
<methodparam><type>array</type><parameter>criteria</parameter></methodparam>
<methodparam choice="opt"><type>boolean</type><parameter>justOne</parameter><initializer>&false;</initializer></methodparam>
<methodparam choice="opt"><type>array</type><parameter>options</parameter><initializer>array()</initializer></methodparam>
</methodsynopsis>
</refsect1>
@ -32,11 +32,29 @@
</varlistentry>
<varlistentry>
<term>
<parameter>justOne</parameter>
<parameter>options</parameter>
</term>
<listitem>
<para>
Remove at most one record matching this criteria.
Options for remove.
<itemizedlist>
<listitem>
<para>
<literal>"justOne"</literal>
</para>
<para>
Remove at most one record matching this criteria.
</para>
</listitem>
<listitem>
<para>
<literal>"safe"</literal>
</para>
<para>
Check that the remove succeeded and how many items were removed.
</para>
</listitem>
</itemizedlist>
</para>
</listitem>
</varlistentry>
@ -47,7 +65,43 @@
<refsect1 role="returnvalues">
&reftitle.returnvalues;
<para>
Returns if the command was executed successfully.
If "safe" is set, returns an associative array with the status of the remove
("ok"), the number of items removed ("n"), and any error that may have
occured ("err"). Otherwise, returns &true; if the remove was successfully
sent, &false; otherwise.
</para>
</refsect1>
<refsect1 role="errors">
&reftitle.errors;
<para>
Throws MongoCursorException if the "safe" option is set and the remove fails.
</para>
</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.0.5</entry>
<entry>
Changed second parameter to an array of options. Pre-1.0.5, the
second parameter was a boolean indicating the "justOne" option and
there was no safe option.
</entry>
</row>
</tbody>
</tgroup>
</informaltable>
</para>
</refsect1>
@ -68,7 +122,7 @@ $halflife = $remaining/2;
// remove half of it
while ($halflife > 0) {
$uranium->remove(array('type' => 94), true);
$uranium->remove(array('type' => 94), array("justOne" => true));
$halflife--;
}

View file

@ -10,8 +10,9 @@
<refsect1 role="description">
&reftitle.description;
<methodsynopsis>
<modifier>public</modifier> <type>boolean</type><methodname>MongoCollection::save</methodname>
<modifier>public</modifier> <type>mixed</type><methodname>MongoCollection::save</methodname>
<methodparam><type>array</type><parameter>a</parameter></methodparam>
<methodparam choice="opt"><type>array</type><parameter>options</parameter><initializer>array()</initializer></methodparam>
</methodsynopsis>
<para>
If the object is from the database, update the existing database object, otherwise
@ -32,6 +33,26 @@
Array to save.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>
<parameter>options</parameter>
</term>
<listitem>
<para>
Options for the save.
<itemizedlist>
<listitem>
<para>
<literal>"safe"</literal>
</para>
<para>
Check that the save succeeded.
</para>
</listitem>
</itemizedlist>
</para>
</listitem>
</varlistentry>
</variablelist>
</para>
@ -44,6 +65,38 @@
</para>
</refsect1>
<refsect1 role="errors">
&reftitle.errors;
<para>
Throws <classname>MongoCursorException</classname> if the "safe" option is
set and the save fails.
</para>
</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.0.5</entry>
<entry>
Added "options" parameter.
</entry>
</row>
</tbody>
</tgroup>
</informaltable>
</para>
</refsect1>
<refsect1 role="examples">
&reftitle.examples;
<example>

View file

@ -13,7 +13,7 @@
<modifier>public</modifier> <type>boolean</type><methodname>MongoCollection::update</methodname>
<methodparam><type>array</type><parameter>criteria</parameter></methodparam>
<methodparam><type>array</type><parameter>newobj</parameter></methodparam>
<methodparam choice="opt"><type>array</type><parameter>options</parameter><initializer>&null;</initializer></methodparam>
<methodparam choice="opt"><type>array</type><parameter>options</parameter><initializer>array()</initializer></methodparam>
</methodsynopsis>
</refsect1>
@ -74,6 +74,14 @@
may change its default behavior at some point in the future.
</para>
</listitem>
<listitem>
<para>
<literal>"safe"</literal>
</para>
<para>
Check that the update succeeded.
</para>
</listitem>
</itemizedlist>
</para>
</listitem>
@ -81,12 +89,22 @@
</variablelist>
</para>
</refsect1>
<refsect1 role="returnvalues">
&reftitle.returnvalues;
<para>
Returns if the update was successfully sent to the database.
</para>
</refsect1>
<refsect1 role="errors">
&reftitle.errors;
<para>
Throws <classname>MongoCursorException</classname> if the "safe" option is
set and the update fails.
</para>
</refsect1>
<refsect1 role="changelog">
&reftitle.changelog;
<para>
@ -106,11 +124,18 @@
second parameter was an optional boolean value specifying an upsert.
</entry>
</row>
<row>
<entry>1.0.5</entry>
<entry>
Added "safe" option.
</entry>
</row>
</tbody>
</tgroup>
</informaltable>
</para>
</refsect1>
<refsect1 role="examples">
&reftitle.examples;
<example>

View file

@ -1,16 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->
<refentry xml:id="mongocursor.getquery" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
<refentry xml:id="mongocursor.info" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
<refnamediv>
<refname>MongoCursor::getQuery</refname>
<refname>MongoCursor::info</refname>
<refpurpose>Gets the query, fields, limit, and skip for this cursor</refpurpose>
</refnamediv>
<refsect1 role="description">
&reftitle.description;
<methodsynopsis>
<modifier>public</modifier> <type>array</type><methodname>MongoCursor::getQuery</methodname>
<modifier>public</modifier> <type>array</type><methodname>MongoCursor::info</methodname>
<void/>
</methodsynopsis>
<para>
@ -33,14 +33,14 @@
<refsect1 role="examples">
&reftitle.examples;
<example>
<title><function>MongoCursor::getQuery</function> example</title>
<title><function>MongoCursor::info</function> example</title>
<programlisting role="php">
<![CDATA[
<?php
$m = new Mongo();
$cursor = $m->foo->bar->find(array("x" => 4), array("y" => false));
var_dump($cursor->getQuery());
var_dump($cursor->info());
?>
]]>

View file

@ -13,6 +13,7 @@
<modifier>public</modifier> <type>mixed</type><methodname>MongoGridFS::storeBytes</methodname>
<methodparam><type>string</type><parameter>bytes</parameter></methodparam>
<methodparam choice="opt"><type>array</type><parameter>extra</parameter><initializer>array()</initializer></methodparam>
<methodparam choice="opt"><type>array</type><parameter>options</parameter><initializer>array()</initializer></methodparam>
</methodsynopsis>
</refsect1>
@ -40,6 +41,26 @@
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>
<parameter>options</parameter>
</term>
<listitem>
<para>
Options for the store.
<itemizedlist>
<listitem>
<para>
<literal>"safe"</literal>
</para>
<para>
Check that this store succeeded.
</para>
</listitem>
</itemizedlist>
</para>
</listitem>
</varlistentry>
</variablelist>
</para>
</refsect1>
@ -51,6 +72,14 @@
</para>
</refsect1>
<refsect1 role="errors">
&reftitle.errors;
<para>
Throws <classname>MongoCursorException</classname> if the "safe" option is
set and the insert fails.
</para>
</refsect1>
</refentry>
<!-- Keep this comment at the end of the file
Local variables:

View file

@ -13,6 +13,7 @@
<modifier>public</modifier> <type>mixed</type><methodname>MongoGridFS::storeFile</methodname>
<methodparam><type>string</type><parameter>filename</parameter></methodparam>
<methodparam choice="opt"><type>array</type><parameter>extra</parameter><initializer>array()</initializer></methodparam>
<methodparam choice="opt"><type>array</type><parameter>options</parameter><initializer>array()</initializer></methodparam>
</methodsynopsis>
</refsect1>
@ -40,6 +41,26 @@
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>
<parameter>options</parameter>
</term>
<listitem>
<para>
Options for the store.
<itemizedlist>
<listitem>
<para>
<literal>"safe"</literal>
</para>
<para>
Check that this store succeeded.
</para>
</listitem>
</itemizedlist>
</para>
</listitem>
</varlistentry>
</variablelist>
</para>
</refsect1>
@ -51,6 +72,14 @@
</para>
</refsect1>
<refsect1 role="errors">
&reftitle.errors;
<para>
Throws <classname>MongoCursorException</classname> if the "safe" option is
set and the insert fails.
</para>
</refsect1>
</refentry>
<!-- Keep this comment at the end of the file
Local variables:

View file

@ -89,7 +89,7 @@
<function name='mongocursor::dead' from='PECL mongo &gt;=0.9.6'/>
<function name='mongocursor::immortal' from='PECL mongo &gt;=1.0.1'/>
<function name='mongocursor::addoption' from='PECL mongo &gt;=1.0.4'/>
<function name='mongocursor::getquery' from='PECL mongo &gt;=1.0.5'/>
<function name='mongocursor::info' from='PECL mongo &gt;=1.0.5'/>
<!-- MongoGridFS -->
<function name='mongogridfs::__construct' from='PECL mongo &gt;=0.9.0'/>
<function name='mongogridfs::find' from='PECL mongo &gt;=0.9.0'/>