Zend_Service_WindowsAzure_Table.xml 27 KB

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