Zend_Service_WindowsAzure_Table.xml 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!-- EN-Revision: 19828 -->
  3. <!-- Reviewed: no -->
  4. <sect1 id="zend.service.windowsazure.storage.table">
  5. <title>Zend_Service_WindowsAzure_Storage_Table</title>
  6. <para>
  7. The Table service offers structured storage in the form of tables.
  8. </para>
  9. <para>
  10. Table Storage is offered by Windows Azure as a REST API which is wrapped by the
  11. <classname>Zend_Service_WindowsAzure_Storage_Table</classname> class in order to provide a
  12. native PHP interface to the storage account.
  13. </para>
  14. <para>
  15. This topic lists some examples of using the
  16. <classname>Zend_Service_WindowsAzure_Storage_Table</classname> class. Other features are
  17. available in the download package, as well as a detailed API documentation of those
  18. features.
  19. </para>
  20. <para>
  21. Note that development table storage (in the Windows Azure SDK) does not support all features
  22. provided by the API. Therefore, the examples listed on this page are to be used on Windows
  23. Azure production table storage.
  24. </para>
  25. <sect2 id="zend.service.windowsazure.storage.table.api">
  26. <title>Operations on tables</title>
  27. <para>
  28. This topic lists some samples of operations that can be executed on tables.
  29. </para>
  30. <sect3 id="zend.service.windowsazure.storage.table.api.create">
  31. <title>Creating a table</title>
  32. <para>
  33. Using the following code, a table can be created on Windows Azure production table
  34. storage.
  35. </para>
  36. <example id="zend.service.windowsazure.storage.table.api.create.example">
  37. <title>Creating a table</title>
  38. <programlisting language="php"><![CDATA[
  39. $storageClient = new Zend_Service_WindowsAzure_Storage_Table(
  40. 'table.core.windows.net', 'myaccount', 'myauthkey'
  41. );
  42. $result = $storageClient->createTable('testtable');
  43. echo 'New table name is: ' . $result->Name;
  44. ]]></programlisting>
  45. </example>
  46. </sect3>
  47. <sect3 id="zend.service.windowsazure.storage.table.api.list">
  48. <title>Listing all tables</title>
  49. <para>
  50. Using the following code, a list of all tables in Windows Azure production table
  51. storage can be queried.
  52. </para>
  53. <example id="zend.service.windowsazure.storage.table.api.list.example">
  54. <title>Listing all tables</title>
  55. <programlisting language="php"><![CDATA[
  56. $storageClient = new Zend_Service_WindowsAzure_Storage_Table(
  57. 'table.core.windows.net', 'myaccount', 'myauthkey'
  58. );
  59. $result = $storageClient->listTables();
  60. foreach ($result as $table) {
  61. echo 'Table name is: ' . $table->Name . "\r\n";
  62. }
  63. ]]></programlisting>
  64. </example>
  65. </sect3>
  66. </sect2>
  67. <sect2 id="zend.service.windowsazure.storage.table.entities">
  68. <title>Operations on entities</title>
  69. <para>
  70. Tables store data as collections of entities. Entities are similar to rows. An entity
  71. has a primary key and a set of properties. A property is a named, typed-value pair,
  72. similar to a column.
  73. </para>
  74. <para>
  75. The Table service does not enforce any schema for tables, so two entities in the same
  76. table may have different sets of properties. Developers may choose to enforce a schema
  77. on the client side. A table may contain any number of entities.
  78. </para>
  79. <para>
  80. <classname>Zend_Service_WindowsAzure_Storage_Table</classname> provides 2 ways of
  81. working with entities:
  82. </para>
  83. <itemizedlist>
  84. <listitem>
  85. <para>
  86. Enforced schema
  87. </para>
  88. </listitem>
  89. <listitem>
  90. <para>
  91. No enforced schema
  92. </para>
  93. </listitem>
  94. </itemizedlist>
  95. <para>
  96. All examples will make use of the following enforced schema class.
  97. </para>
  98. <example id="zend.service.windowsazure.storage.table.entities.schema">
  99. <title>Enforced schema used in samples</title>
  100. <programlisting language="php"><![CDATA[
  101. class SampleEntity extends Zend_Service_WindowsAzure_Storage_TableEntity
  102. {
  103. /**
  104. * @azure Name
  105. */
  106. public $Name;
  107. /**
  108. * @azure Age Edm.Int64
  109. */
  110. public $Age;
  111. /**
  112. * @azure Visible Edm.Boolean
  113. */
  114. public $Visible = false;
  115. }
  116. ]]></programlisting>
  117. </example>
  118. <para>
  119. Note that if no schema class is passed into table storage methods,
  120. <classname>Zend_Service_WindowsAzure_Storage_Table</classname> automatically works with
  121. <classname>Zend_Service_WindowsAzure_Storage_DynamicTableEntity</classname>.
  122. </para>
  123. <sect3 id="zend.service.windowsazure.storage.table.entities.enforced">
  124. <title>Enforced schema entities</title>
  125. <para>
  126. To enforce a schema on the client side using the
  127. <classname>Zend_Service_WindowsAzure_Storage_Table</classname> class, you can create
  128. a class which inherits
  129. <classname>Zend_Service_WindowsAzure_Storage_TableEntity</classname>. This class
  130. provides some basic functionality for the
  131. <classname>Zend_Service_WindowsAzure_Storage_Table</classname> class to work with a
  132. client-side schema.
  133. </para>
  134. <para>
  135. Base properties provided by
  136. <classname>Zend_Service_WindowsAzure_Storage_TableEntity</classname> are:
  137. </para>
  138. <itemizedlist>
  139. <listitem>
  140. <para>
  141. PartitionKey (exposed through <methodname>getPartitionKey()</methodname> and
  142. <methodname>setPartitionKey()</methodname>)
  143. </para>
  144. </listitem>
  145. <listitem>
  146. <para>
  147. RowKey (exposed through <methodname>getRowKey()</methodname> and
  148. <methodname>setRowKey()</methodname>)
  149. </para>
  150. </listitem>
  151. <listitem>
  152. <para>
  153. Timestamp (exposed through <methodname>getTimestamp()</methodname> and
  154. <methodname>setTimestamp()</methodname>)
  155. </para>
  156. </listitem>
  157. <listitem>
  158. <para>
  159. Etag value (exposed through <methodname>getEtag()</methodname> and
  160. <methodname>setEtag()</methodname>)
  161. </para>
  162. </listitem>
  163. </itemizedlist>
  164. <para>
  165. Here's a sample class inheriting
  166. <classname>Zend_Service_WindowsAzure_Storage_TableEntity</classname>:
  167. </para>
  168. <example id="zend.service.windowsazure.storage.table.entities.enforced.schema">
  169. <title>Sample enforced schema class</title>
  170. <programlisting language="php"><![CDATA[
  171. class SampleEntity extends Zend_Service_WindowsAzure_Storage_TableEntity
  172. {
  173. /**
  174. * @azure Name
  175. */
  176. public $Name;
  177. /**
  178. * @azure Age Edm.Int64
  179. */
  180. public $Age;
  181. /**
  182. * @azure Visible Edm.Boolean
  183. */
  184. public $Visible = false;
  185. }
  186. ]]></programlisting>
  187. </example>
  188. <para>
  189. The <classname>Zend_Service_WindowsAzure_Storage_Table</classname> class will map
  190. any class inherited from
  191. <classname>Zend_Service_WindowsAzure_Storage_TableEntity</classname> to Windows
  192. Azure table storage entities with the correct data type and property name. All there
  193. is to storing a property in Windows Azure is adding a docblock comment to a public
  194. property or public getter/setter, in the following format:
  195. </para>
  196. <example id="zend.service.windowsazure.storage.table.entities.enforced.schema-property">
  197. <title>Enforced property</title>
  198. <programlisting language="php"><![CDATA[
  199. /**
  200. * @azure <property name in Windows Azure> <optional property type>
  201. */
  202. public $<property name in PHP>;
  203. ]]></programlisting>
  204. </example>
  205. <para>
  206. Let's see how to define a propety "Age" as an integer on Windows Azure table
  207. storage:
  208. </para>
  209. <example id="zend.service.windowsazure.storage.table.entities.enforced.schema-property-sample">
  210. <title>Sample enforced property</title>
  211. <programlisting language="php"><![CDATA[
  212. /**
  213. * @azure Age Edm.Int64
  214. */
  215. public $Age;
  216. ]]></programlisting>
  217. </example>
  218. <para>
  219. Note that a property does not necessarily have to be named the same on Windows Azure
  220. table storage. The Windows Azure table storage property name can be defined as well
  221. as the type.
  222. </para>
  223. <para>
  224. The following data types are supported:
  225. </para>
  226. <itemizedlist>
  227. <listitem>
  228. <para>
  229. <constant>Edm.Binary</constant> - An array of bytes up to 64 KB in size.
  230. </para>
  231. </listitem>
  232. <listitem>
  233. <para>
  234. <constant>Edm.Boolean</constant> - A boolean value.
  235. </para>
  236. </listitem>
  237. <listitem>
  238. <para>
  239. <constant>Edm.DateTime</constant> - A 64-bit value expressed as Coordinated
  240. Universal Time (UTC). The supported DateTime range begins from 12:00
  241. midnight, January 1, 1601 A.D. (C.E.), Coordinated Universal Time (UTC). The
  242. range ends at December 31st, 9999.
  243. </para>
  244. </listitem>
  245. <listitem>
  246. <para>
  247. <constant>Edm.Double</constant> - A 64-bit floating point value.
  248. </para>
  249. </listitem>
  250. <listitem>
  251. <para>
  252. <constant>Edm.Guid</constant> - A 128-bit globally unique identifier.
  253. </para>
  254. </listitem>
  255. <listitem>
  256. <para>
  257. <constant>Edm.Int32</constant> - A 32-bit integer.
  258. </para>
  259. </listitem>
  260. <listitem>
  261. <para>
  262. <constant>Edm.Int64</constant> - A 64-bit integer.
  263. </para>
  264. </listitem>
  265. <listitem>
  266. <para>
  267. <constant>Edm.String</constant> - A UTF-16-encoded value. String values may
  268. be up to 64 KB in size.
  269. </para>
  270. </listitem>
  271. </itemizedlist>
  272. </sect3>
  273. <sect3 id="zend.service.windowsazure.storage.table.entities.dynamic">
  274. <title>No enforced schema entities (a.k.a. DynamicEntity)</title>
  275. <para>
  276. To use the <classname>Zend_Service_WindowsAzure_Storage_Table</classname> class
  277. without defining a schema, you can make use of the
  278. <classname>Zend_Service_WindowsAzure_Storage_DynamicTableEntity</classname> class.
  279. This class inherits <classname>Zend_Service_WindowsAzure_Storage_TableEntity</code>
  280. like an enforced schema class does, but contains additional logic to make it dynamic
  281. and not bound to a schema.
  282. </para>
  283. <para>
  284. Base properties provided by
  285. <classname>Zend_Service_WindowsAzure_Storage_DynamicTableEntity</classname> are:
  286. </para>
  287. <itemizedlist>
  288. <listitem>
  289. <para>
  290. PartitionKey (exposed through <methodname>getPartitionKey()</methodname> and
  291. <methodname>setPartitionKey()</methodname>)
  292. </para>
  293. </listitem>
  294. <listitem>
  295. <para>
  296. RowKey (exposed through <methodname>getRowKey()</methodname> and
  297. <methodname>setRowKey()</methodname>)
  298. </para>
  299. </listitem>
  300. <listitem>
  301. <para>
  302. Timestamp (exposed through <methodname>getTimestamp()</methodname> and
  303. <methodname>setTimestamp()</methodname>)
  304. </para>
  305. </listitem>
  306. <listitem>
  307. <para>
  308. Etag value (exposed through <methodname>getEtag()</methodname> and
  309. <methodname>setEtag()</methodname>)
  310. </para>
  311. </listitem>
  312. </itemizedlist>
  313. <para>
  314. Other properties can be added on the fly. Their Windows Azure table storage type
  315. will be determined on-the-fly:
  316. </para>
  317. <example id="zend.service.windowsazure.storage.table.entities.dynamic.schema">
  318. <title>Dynamicaly adding properties to Zend_Service_WindowsAzure_Storage_DynamicTableEntity</title>
  319. <programlisting language="php"><![CDATA[
  320. $target = new Zend_Service_WindowsAzure_Storage_DynamicTableEntity(
  321. 'partition1', '000001'
  322. );
  323. $target->Name = 'Name'; // Will add property "Name" of type "Edm.String"
  324. $target->Age = 25; // Will add property "Age" of type "Edm.Int32"
  325. ]]></programlisting>
  326. </example>
  327. <para>
  328. Optionally, a property type can be enforced:
  329. </para>
  330. <example id="zend.service.windowsazure.storage.table.entities.dynamic.schema-forcedproperties">
  331. <title>Forcing property types on Zend_Service_WindowsAzure_Storage_DynamicTableEntity</title>
  332. <programlisting language="php"><![CDATA[
  333. $target = new Zend_Service_WindowsAzure_Storage_DynamicTableEntity(
  334. 'partition1', '000001'
  335. );
  336. $target->Name = 'Name'; // Will add property "Name" of type "Edm.String"
  337. $target->Age = 25; // Will add property "Age" of type "Edm.Int32"
  338. // Change type of property "Age" to "Edm.Int32":
  339. $target->setAzurePropertyType('Age', 'Edm.Int64');
  340. ]]></programlisting>
  341. </example>
  342. <para>
  343. The <classname>Zend_Service_WindowsAzure_Storage_Table</classname> class
  344. automatically works with
  345. <classname>Zend_Service_WindowsAzure_Storage_TableEntity</classname> if no specific
  346. class is passed into Table Storage methods.
  347. </para>
  348. </sect3>
  349. <sect3 id="zend.service.windowsazure.storage.table.entities.api">
  350. <title>Entities API examples</title>
  351. <sect4 id="zend.service.windowsazure.storage.table.entities.api.insert">
  352. <title>Inserting an entity</title>
  353. <para>
  354. Using the following code, an entity can be inserted into a table named
  355. "testtable". Note that the table has already been created before.
  356. </para>
  357. <example id="zend.service.windowsazure.storage.table.api.entities.insert.example">
  358. <title>Inserting an entity</title>
  359. <programlisting language="php"><![CDATA[
  360. $entity = new SampleEntity ('partition1', 'row1');
  361. $entity->FullName = "Maarten";
  362. $entity->Age = 25;
  363. $entity->Visible = true;
  364. $storageClient = new Zend_Service_WindowsAzure_Storage_Table(
  365. 'table.core.windows.net', 'myaccount', 'myauthkey'
  366. );
  367. $result = $storageClient->insertEntity('testtable', $entity);
  368. // Check the timestamp and etag of the newly inserted entity
  369. echo 'Timestamp: ' . $result->getTimestamp() . "\n";
  370. echo 'Etag: ' . $result->getEtag() . "\n";
  371. ]]></programlisting>
  372. </example>
  373. </sect4>
  374. <sect4 id="zend.service.windowsazure.storage.table.entities.api.retrieve-by-id">
  375. <title>Retrieving an entity by partition key and row key</title>
  376. <para>
  377. Using the following code, an entity can be retrieved by partition key and row
  378. key. Note that the table and entity have already been created before.
  379. </para>
  380. <example id="zend.service.windowsazure.storage.table.entities.api.retrieve-by-id.example">
  381. <title>Retrieving an entity by partition key and row key</title>
  382. <programlisting language="php"><![CDATA[
  383. $storageClient = new Zend_Service_WindowsAzure_Storage_Table(
  384. 'table.core.windows.net', 'myaccount', 'myauthkey'
  385. );
  386. $entity= $storageClient->retrieveEntityById(
  387. 'testtable', 'partition1', 'row1', 'SampleEntity'
  388. );
  389. ]]></programlisting>
  390. </example>
  391. </sect4>
  392. <sect4 id="zend.service.windowsazure.storage.table.entities.api.updating">
  393. <title>Updating an entity</title>
  394. <para>
  395. Using the following code, an entity can be updated. Note that the table and
  396. entity have already been created before.
  397. </para>
  398. <example id="zend.service.windowsazure.storage.table.api.entities.updating.example">
  399. <title>Updating an entity</title>
  400. <programlisting language="php"><![CDATA[
  401. $storageClient = new Zend_Service_WindowsAzure_Storage_Table(
  402. 'table.core.windows.net', 'myaccount', 'myauthkey'
  403. );
  404. $entity = $storageClient->retrieveEntityById(
  405. 'testtable', 'partition1', 'row1', 'SampleEntity'
  406. );
  407. $entity->Name = 'New name';
  408. $result = $storageClient->updateEntity('testtable', $entity);
  409. ]]></programlisting>
  410. </example>
  411. <para>
  412. If you want to make sure the entity has not been updated before, you can make
  413. sure the <acronym>Etag</acronym> of the entity is checked. If the entity already
  414. has had an update, the update will fail to make sure you do not overwrite any
  415. newer data.
  416. </para>
  417. <example id="zend.service.windowsazure.storage.table.entities.api.updating.example-etag">
  418. <title>Updating an entity (with Etag check)</title>
  419. <programlisting language="php"><![CDATA[
  420. $storageClient = new Zend_Service_WindowsAzure_Storage_Table(
  421. 'table.core.windows.net', 'myaccount', 'myauthkey'
  422. );
  423. $entity = $storageClient->retrieveEntityById(
  424. 'testtable', 'partition1', 'row1', 'SampleEntity'
  425. );
  426. $entity->Name = 'New name';
  427. // last parameter instructs the Etag check:
  428. $result = $storageClient->updateEntity('testtable', $entity, true);
  429. ]]></programlisting>
  430. </example>
  431. </sect4>
  432. <sect4 id="zend.service.windowsazure.storage.table.entities.api.delete">
  433. <title>Deleting an entity</title>
  434. <para>
  435. Using the following code, an entity can be deleted. Note that the table and
  436. entity have already been created before.
  437. </para>
  438. <example id="zend.service.windowsazure.storage.table.entities.api.delete.example">
  439. <title>Deleting an entity</title>
  440. <programlisting language="php"><![CDATA[
  441. $storageClient = new Zend_Service_WindowsAzure_Storage_Table(
  442. 'table.core.windows.net', 'myaccount', 'myauthkey'
  443. );
  444. $entity = $storageClient->retrieveEntityById(
  445. 'testtable', 'partition1', 'row1', 'SampleEntity'
  446. );
  447. $result = $storageClient->deleteEntity('testtable', $entity);
  448. ]]></programlisting>
  449. </example>
  450. </sect4>
  451. </sect3>
  452. <sect3 id="zend.service.windowsazure.storage.table.entities.querying">
  453. <title>Performing queries</title>
  454. <para>
  455. Queries in <classname>Zend_Service_WindowsAzure_Storage_Table</classname> table
  456. storage can be performed in two ways:
  457. </para>
  458. <itemizedlist>
  459. <listitem>
  460. <para>
  461. By manually creating a filter condition (involving learning a new query
  462. language)
  463. </para>
  464. </listitem>
  465. <listitem>
  466. <para>
  467. By using the fluent interface provided by the
  468. <classname>Zend_Service_WindowsAzure_Storage_Table</classname>
  469. </para>
  470. </listitem>
  471. </itemizedlist>
  472. <para>
  473. Using the following code, a table can be queried using a filter condition. Note
  474. that the table and entities have already been created before.
  475. </para>
  476. <example id="zend.service.windowsazure.storage.table.entities.querying.query-filter">
  477. <title>Performing queries using a filter condition</title>
  478. <programlisting language="php"><![CDATA[
  479. $storageClient = new Zend_Service_WindowsAzure_Storage_Table(
  480. 'table.core.windows.net', 'myaccount', 'myauthkey'
  481. );
  482. $entities = $storageClient->storageClient->retrieveEntities(
  483. 'testtable',
  484. 'Name eq \'Maarten\' and PartitionKey eq \'partition1\'',
  485. 'SampleEntity'
  486. );
  487. foreach ($entities as $entity) {
  488. echo 'Name: ' . $entity->Name . "\n";
  489. }
  490. ]]></programlisting>
  491. </example>
  492. <para>
  493. Using the following code, a table can be queried using a fluent interface. Note
  494. that the table and entities have already been created before.
  495. </para>
  496. <example id="zend.service.windowsazure.storage.table.api.entities.query-fluent">
  497. <title>Performing queries using a fluent interface</title>
  498. <programlisting language="php"><![CDATA[
  499. $storageClient = new Zend_Service_WindowsAzure_Storage_Table(
  500. 'table.core.windows.net', 'myaccount', 'myauthkey'
  501. );
  502. $entities = $storageClient->storageClient->retrieveEntities(
  503. 'testtable',
  504. $storageClient->select()
  505. ->from($tableName)
  506. ->where('Name eq ?', 'Maarten')
  507. ->andWhere('PartitionKey eq ?', 'partition1'),
  508. 'SampleEntity'
  509. );
  510. foreach ($entities as $entity) {
  511. echo 'Name: ' . $entity->Name . "\n";
  512. }
  513. ]]></programlisting>
  514. </example>
  515. </sect3>
  516. <sect3 id="zend.service.windowsazure.storage.table.entities.batch">
  517. <title>Batch operations</title>
  518. <para>
  519. This topic demonstrates how to use the table entity group transaction features
  520. provided by Windows Azure table storage. Windows Azure table storage supports batch
  521. transactions on entities that are in the same table and belong to the same partition
  522. group. A transaction can include at most 100 entities.
  523. </para>
  524. <para>
  525. The following example uses a batch operation (transaction) to insert a set of
  526. entities into the "testtable" table. Note that the table has already been created
  527. before.
  528. </para>
  529. <example id="zend.service.windowsazure.storage.table.api.batch">
  530. <title>Executing a batch operation</title>
  531. <programlisting language="php"><![CDATA[
  532. $storageClient = new Zend_Service_WindowsAzure_Storage_Table(
  533. 'table.core.windows.net', 'myaccount', 'myauthkey'
  534. );
  535. // Start batch
  536. $batch = $storageClient->startBatch();
  537. // Insert entities in batch
  538. $entities = generateEntities();
  539. foreach ($entities as $entity) {
  540. $storageClient->insertEntity($tableName, $entity);
  541. }
  542. // Commit
  543. $batch->commit();
  544. ]]></programlisting>
  545. </example>
  546. </sect3>
  547. </sect2>
  548. <sect2 id="zend.service.windowsazure.storage.table.sessionhandler">
  549. <title>Table storage session handler</title>
  550. <para>
  551. When running a PHP application on the Windows Azure platform in a load-balanced mode
  552. (running 2 Web Role instances or more), it is important that PHP session data can be
  553. shared between multiple Web Role instances. The Windows Azure SDK for PHP provides the
  554. <classname>Zend_Service_WindowsAzure_SessionHandler</classname> class, which uses
  555. Windows Azure Table Storage as a session handler for PHP applications.
  556. </para>
  557. <para>
  558. To use the <classname>Zend_Service_WindowsAzure_SessionHandler</classname> session
  559. handler, it should be registered as the default session handler for your PHP
  560. application:
  561. </para>
  562. <example id="zend.service.windowsazure.storage.table.api.sessionhandler-register">
  563. <title>Registering table storage session handler</title>
  564. <programlisting language="php"><![CDATA[
  565. $storageClient = new Zend_Service_WindowsAzure_Storage_Table(
  566. 'table.core.windows.net', 'myaccount', 'myauthkey'
  567. );
  568. $sessionHandler = new Zend_Service_WindowsAzure_SessionHandler(
  569. $storageClient , 'sessionstable'
  570. );
  571. $sessionHandler->register();
  572. ]]></programlisting>
  573. </example>
  574. <para>
  575. The above classname registers the
  576. <classname>Zend_Service_WindowsAzure_SessionHandler</classname> session handler and will
  577. store sessions in a table called "sessionstable".
  578. </para>
  579. <para>
  580. After registration of the
  581. <classname>Zend_Service_WindowsAzure_SessionHandler</classname> session handler,
  582. sessions can be started and used in the same way as a normal PHP session:
  583. </para>
  584. <example id="zend.service.windowsazure.storage.table.api.sessionhandler-usage">
  585. <title>Using table storage session handler</title>
  586. <programlisting role="php"><![CDATA[
  587. $storageClient = new Zend_Service_WindowsAzure_Storage_Table(
  588. 'table.core.windows.net', 'myaccount', 'myauthkey'
  589. );
  590. $sessionHandler = new Zend_Service_WindowsAzure_SessionHandler(
  591. $storageClient , 'sessionstable'
  592. );
  593. $sessionHandler->register();
  594. session_start();
  595. if (!isset($_SESSION['firstVisit'])) {
  596. $_SESSION['firstVisit'] = time();
  597. }
  598. // ...
  599. ]]></programlisting>
  600. </example>
  601. <warning>
  602. <para>
  603. The <classname>Zend_Service_WindowsAzure_SessionHandler</classname> session handler
  604. should be registered before a call to <functionname>session_start()</functionname>
  605. is made!
  606. </para>
  607. </warning>
  608. </sect2>
  609. </sect1>