Zend_Service_WindowsAzure_Table.xml 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738
  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 API which is wrapped by the
  10. <classname>Zend_Service_WindowsAzure_Storage_Table</classname> class in order to provide a
  11. native PHP 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 API documentation of those
  17. features.
  18. </para>
  19. <para>
  20. Note that development table storage (in the Windows Azure SDK) does not support all features
  21. provided by the API. Therefore, the examples listed on this page are to be used on Windows
  22. 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 id="zend.service.windowsazure.storage.table.entities.enforced.schema-property-sample">
  209. <title>Sample enforced property</title>
  210. <programlisting language="php"><![CDATA[
  211. /**
  212. * @azure Age Edm.Int64
  213. */
  214. public $Age;
  215. ]]></programlisting>
  216. </example>
  217. <para>
  218. Note that a property does not necessarily have to be named the same on Windows Azure
  219. table storage. The Windows Azure table storage property name can be defined as well
  220. as the type.
  221. </para>
  222. <para>
  223. The following data types are supported:
  224. </para>
  225. <itemizedlist>
  226. <listitem>
  227. <para>
  228. <constant>Edm.Binary</constant> - An array of bytes up to 64 KB in size.
  229. </para>
  230. </listitem>
  231. <listitem>
  232. <para>
  233. <constant>Edm.Boolean</constant> - A boolean value.
  234. </para>
  235. </listitem>
  236. <listitem>
  237. <para>
  238. <constant>Edm.DateTime</constant> - A 64-bit value expressed as Coordinated
  239. Universal Time (UTC). The supported DateTime range begins from 12:00
  240. midnight, January 1, 1601 A.D. (C.E.), Coordinated Universal Time (UTC). The
  241. range ends at December 31st, 9999.
  242. </para>
  243. </listitem>
  244. <listitem>
  245. <para>
  246. <constant>Edm.Double</constant> - A 64-bit floating point value.
  247. </para>
  248. </listitem>
  249. <listitem>
  250. <para>
  251. <constant>Edm.Guid</constant> - A 128-bit globally unique identifier.
  252. </para>
  253. </listitem>
  254. <listitem>
  255. <para>
  256. <constant>Edm.Int32</constant> - A 32-bit integer.
  257. </para>
  258. </listitem>
  259. <listitem>
  260. <para>
  261. <constant>Edm.Int64</constant> - A 64-bit integer.
  262. </para>
  263. </listitem>
  264. <listitem>
  265. <para>
  266. <constant>Edm.String</constant> - A UTF-16-encoded value. String values may
  267. be up to 64 KB in size.
  268. </para>
  269. </listitem>
  270. </itemizedlist>
  271. </sect3>
  272. <sect3 id="zend.service.windowsazure.storage.table.entities.dynamic">
  273. <title>No enforced schema entities (a.k.a. DynamicEntity)</title>
  274. <para>
  275. To use the <classname>Zend_Service_WindowsAzure_Storage_Table</classname> class
  276. without defining a schema, you can make use of the
  277. <classname>Zend_Service_WindowsAzure_Storage_DynamicTableEntity</classname> class.
  278. This class inherits <classname>Zend_Service_WindowsAzure_Storage_TableEntity</classname>
  279. like an enforced schema class does, but contains additional logic to make it dynamic
  280. and not bound to a schema.
  281. </para>
  282. <para>
  283. Base properties provided by
  284. <classname>Zend_Service_WindowsAzure_Storage_DynamicTableEntity</classname> are:
  285. </para>
  286. <itemizedlist>
  287. <listitem>
  288. <para>
  289. PartitionKey (exposed through <methodname>getPartitionKey()</methodname> and
  290. <methodname>setPartitionKey()</methodname>)
  291. </para>
  292. </listitem>
  293. <listitem>
  294. <para>
  295. RowKey (exposed through <methodname>getRowKey()</methodname> and
  296. <methodname>setRowKey()</methodname>)
  297. </para>
  298. </listitem>
  299. <listitem>
  300. <para>
  301. Timestamp (exposed through <methodname>getTimestamp()</methodname> and
  302. <methodname>setTimestamp()</methodname>)
  303. </para>
  304. </listitem>
  305. <listitem>
  306. <para>
  307. Etag value (exposed through <methodname>getEtag()</methodname> and
  308. <methodname>setEtag()</methodname>)
  309. </para>
  310. </listitem>
  311. </itemizedlist>
  312. <para>
  313. Other properties can be added on the fly. Their Windows Azure table storage type
  314. will be determined on-the-fly:
  315. </para>
  316. <example id="zend.service.windowsazure.storage.table.entities.dynamic.schema">
  317. <title>Dynamicaly adding properties to Zend_Service_WindowsAzure_Storage_DynamicTableEntity</title>
  318. <programlisting language="php"><![CDATA[
  319. $target = new Zend_Service_WindowsAzure_Storage_DynamicTableEntity(
  320. 'partition1', '000001'
  321. );
  322. $target->Name = 'Name'; // Will add property "Name" of type "Edm.String"
  323. $target->Age = 25; // Will add property "Age" of type "Edm.Int32"
  324. ]]></programlisting>
  325. </example>
  326. <para>
  327. Optionally, a property type can be enforced:
  328. </para>
  329. <example id="zend.service.windowsazure.storage.table.entities.dynamic.schema-forcedproperties">
  330. <title>Forcing property types on Zend_Service_WindowsAzure_Storage_DynamicTableEntity</title>
  331. <programlisting language="php"><![CDATA[
  332. $target = new Zend_Service_WindowsAzure_Storage_DynamicTableEntity(
  333. 'partition1', '000001'
  334. );
  335. $target->Name = 'Name'; // Will add property "Name" of type "Edm.String"
  336. $target->Age = 25; // Will add property "Age" of type "Edm.Int32"
  337. // Change type of property "Age" to "Edm.Int32":
  338. $target->setAzurePropertyType('Age', 'Edm.Int64');
  339. ]]></programlisting>
  340. </example>
  341. <para>
  342. The <classname>Zend_Service_WindowsAzure_Storage_Table</classname> class
  343. automatically works with
  344. <classname>Zend_Service_WindowsAzure_Storage_TableEntity</classname> if no specific
  345. class is passed into Table Storage methods.
  346. </para>
  347. </sect3>
  348. <sect3 id="zend.service.windowsazure.storage.table.entities.api">
  349. <title>Entities API examples</title>
  350. <sect4 id="zend.service.windowsazure.storage.table.entities.api.insert">
  351. <title>Inserting an entity</title>
  352. <para>
  353. Using the following code, an entity can be inserted into a table named
  354. "testtable". Note that the table has already been created before.
  355. </para>
  356. <example id="zend.service.windowsazure.storage.table.api.entities.insert.example">
  357. <title>Inserting an entity</title>
  358. <programlisting language="php"><![CDATA[
  359. $entity = new SampleEntity ('partition1', 'row1');
  360. $entity->FullName = "Maarten";
  361. $entity->Age = 25;
  362. $entity->Visible = true;
  363. $storageClient = new Zend_Service_WindowsAzure_Storage_Table(
  364. 'table.core.windows.net', 'myaccount', 'myauthkey'
  365. );
  366. $result = $storageClient->insertEntity('testtable', $entity);
  367. // Check the timestamp and etag of the newly inserted entity
  368. echo 'Timestamp: ' . $result->getTimestamp() . "\n";
  369. echo 'Etag: ' . $result->getEtag() . "\n";
  370. ]]></programlisting>
  371. </example>
  372. </sect4>
  373. <sect4 id="zend.service.windowsazure.storage.table.entities.api.retrieve-by-id">
  374. <title>Retrieving an entity by partition key and row key</title>
  375. <para>
  376. Using the following code, an entity can be retrieved by partition key and row
  377. key. Note that the table and entity have already been created before.
  378. </para>
  379. <example id="zend.service.windowsazure.storage.table.entities.api.retrieve-by-id.example">
  380. <title>Retrieving an entity by partition key and row key</title>
  381. <programlisting language="php"><![CDATA[
  382. $storageClient = new Zend_Service_WindowsAzure_Storage_Table(
  383. 'table.core.windows.net', 'myaccount', 'myauthkey'
  384. );
  385. $entity= $storageClient->retrieveEntityById(
  386. 'testtable', 'partition1', 'row1', 'SampleEntity'
  387. );
  388. ]]></programlisting>
  389. </example>
  390. </sect4>
  391. <sect4 id="zend.service.windowsazure.storage.table.entities.api.updating">
  392. <title>Updating an entity</title>
  393. <para>
  394. Using the following code, an entity can be updated. Note that the table and
  395. entity have already been created before.
  396. </para>
  397. <example id="zend.service.windowsazure.storage.table.api.entities.updating.example">
  398. <title>Updating an entity</title>
  399. <programlisting language="php"><![CDATA[
  400. $storageClient = new Zend_Service_WindowsAzure_Storage_Table(
  401. 'table.core.windows.net', 'myaccount', 'myauthkey'
  402. );
  403. $entity = $storageClient->retrieveEntityById(
  404. 'testtable', 'partition1', 'row1', 'SampleEntity'
  405. );
  406. $entity->Name = 'New name';
  407. $result = $storageClient->updateEntity('testtable', $entity);
  408. ]]></programlisting>
  409. </example>
  410. <para>
  411. If you want to make sure the entity has not been updated before, you can make
  412. sure the <acronym>Etag</acronym> of the entity is checked. If the entity already
  413. has had an update, the update will fail to make sure you do not overwrite any
  414. newer data.
  415. </para>
  416. <example id="zend.service.windowsazure.storage.table.entities.api.updating.example-etag">
  417. <title>Updating an entity (with Etag check)</title>
  418. <programlisting language="php"><![CDATA[
  419. $storageClient = new Zend_Service_WindowsAzure_Storage_Table(
  420. 'table.core.windows.net', 'myaccount', 'myauthkey'
  421. );
  422. $entity = $storageClient->retrieveEntityById(
  423. 'testtable', 'partition1', 'row1', 'SampleEntity'
  424. );
  425. $entity->Name = 'New name';
  426. // last parameter instructs the Etag check:
  427. $result = $storageClient->updateEntity('testtable', $entity, true);
  428. ]]></programlisting>
  429. </example>
  430. </sect4>
  431. <sect4 id="zend.service.windowsazure.storage.table.entities.api.delete">
  432. <title>Deleting an entity</title>
  433. <para>
  434. Using the following code, an entity can be deleted. Note that the table and
  435. entity have already been created before.
  436. </para>
  437. <example id="zend.service.windowsazure.storage.table.entities.api.delete.example">
  438. <title>Deleting an entity</title>
  439. <programlisting language="php"><![CDATA[
  440. $storageClient = new Zend_Service_WindowsAzure_Storage_Table(
  441. 'table.core.windows.net', 'myaccount', 'myauthkey'
  442. );
  443. $entity = $storageClient->retrieveEntityById(
  444. 'testtable', 'partition1', 'row1', 'SampleEntity'
  445. );
  446. $result = $storageClient->deleteEntity('testtable', $entity);
  447. ]]></programlisting>
  448. </example>
  449. </sect4>
  450. </sect3>
  451. <sect3 id="zend.service.windowsazure.storage.table.entities.querying">
  452. <title>Performing queries</title>
  453. <para>
  454. Queries in <classname>Zend_Service_WindowsAzure_Storage_Table</classname> table
  455. storage can be performed in two ways:
  456. </para>
  457. <itemizedlist>
  458. <listitem>
  459. <para>
  460. By manually creating a filter condition (involving learning a new query
  461. language)
  462. </para>
  463. </listitem>
  464. <listitem>
  465. <para>
  466. By using the fluent interface provided by the
  467. <classname>Zend_Service_WindowsAzure_Storage_Table</classname>
  468. </para>
  469. </listitem>
  470. </itemizedlist>
  471. <para>
  472. Using the following code, a table can be queried using a filter condition. Note
  473. that the table and entities have already been created before.
  474. </para>
  475. <example id="zend.service.windowsazure.storage.table.entities.querying.query-filter">
  476. <title>Performing queries using a filter condition</title>
  477. <programlisting language="php"><![CDATA[
  478. $storageClient = new Zend_Service_WindowsAzure_Storage_Table(
  479. 'table.core.windows.net', 'myaccount', 'myauthkey'
  480. );
  481. $entities = $storageClient->storageClient->retrieveEntities(
  482. 'testtable',
  483. 'Name eq \'Maarten\' and PartitionKey eq \'partition1\'',
  484. 'SampleEntity'
  485. );
  486. foreach ($entities as $entity) {
  487. echo 'Name: ' . $entity->Name . "\n";
  488. }
  489. ]]></programlisting>
  490. </example>
  491. <para>
  492. Using the following code, a table can be queried using a fluent interface. Note
  493. that the table and entities have already been created before.
  494. </para>
  495. <example id="zend.service.windowsazure.storage.table.api.entities.query-fluent">
  496. <title>Performing queries using a fluent interface</title>
  497. <programlisting language="php"><![CDATA[
  498. $storageClient = new Zend_Service_WindowsAzure_Storage_Table(
  499. 'table.core.windows.net', 'myaccount', 'myauthkey'
  500. );
  501. $entities = $storageClient->storageClient->retrieveEntities(
  502. 'testtable',
  503. $storageClient->select()
  504. ->from($tableName)
  505. ->where('Name eq ?', 'Maarten')
  506. ->andWhere('PartitionKey eq ?', 'partition1'),
  507. 'SampleEntity'
  508. );
  509. foreach ($entities as $entity) {
  510. echo 'Name: ' . $entity->Name . "\n";
  511. }
  512. ]]></programlisting>
  513. </example>
  514. </sect3>
  515. <sect3 id="zend.service.windowsazure.storage.table.entities.batch">
  516. <title>Batch operations</title>
  517. <para>
  518. This topic demonstrates how to use the table entity group transaction features
  519. provided by Windows Azure table storage. Windows Azure table storage supports batch
  520. transactions on entities that are in the same table and belong to the same partition
  521. group. A transaction can include at most 100 entities.
  522. </para>
  523. <para>
  524. The following example uses a batch operation (transaction) to insert a set of
  525. entities into the "testtable" table. Note that the table has already been created
  526. before.
  527. </para>
  528. <example id="zend.service.windowsazure.storage.table.api.batch">
  529. <title>Executing a batch operation</title>
  530. <programlisting language="php"><![CDATA[
  531. $storageClient = new Zend_Service_WindowsAzure_Storage_Table(
  532. 'table.core.windows.net', 'myaccount', 'myauthkey'
  533. );
  534. // Start batch
  535. $batch = $storageClient->startBatch();
  536. // Insert entities in batch
  537. $entities = generateEntities();
  538. foreach ($entities as $entity) {
  539. $storageClient->insertEntity($tableName, $entity);
  540. }
  541. // Commit
  542. $batch->commit();
  543. ]]></programlisting>
  544. </example>
  545. </sect3>
  546. </sect2>
  547. <sect2 id="zend.service.windowsazure.storage.table.sessionhandler">
  548. <title>Table storage session handler</title>
  549. <para>
  550. When running a PHP application on the Windows Azure platform in a load-balanced mode
  551. (running 2 Web Role instances or more), it is important that PHP session data can be
  552. shared between multiple Web Role instances. The Windows Azure SDK for PHP provides the
  553. <classname>Zend_Service_WindowsAzure_SessionHandler</classname> class, which uses
  554. Windows Azure Table Storage as a session handler for PHP applications.
  555. </para>
  556. <para>
  557. To use the <classname>Zend_Service_WindowsAzure_SessionHandler</classname> session
  558. handler, it should be registered as the default session handler for your PHP
  559. application:
  560. </para>
  561. <example id="zend.service.windowsazure.storage.table.api.sessionhandler-register">
  562. <title>Registering table storage session handler</title>
  563. <programlisting language="php"><![CDATA[
  564. $storageClient = new Zend_Service_WindowsAzure_Storage_Table(
  565. 'table.core.windows.net', 'myaccount', 'myauthkey'
  566. );
  567. $sessionHandler = new Zend_Service_WindowsAzure_SessionHandler(
  568. $storageClient , 'sessionstable'
  569. );
  570. $sessionHandler->register();
  571. ]]></programlisting>
  572. </example>
  573. <para>
  574. The above classname registers the
  575. <classname>Zend_Service_WindowsAzure_SessionHandler</classname> session handler and will
  576. store sessions in a table called "sessionstable".
  577. </para>
  578. <para>
  579. After registration of the
  580. <classname>Zend_Service_WindowsAzure_SessionHandler</classname> session handler,
  581. sessions can be started and used in the same way as a normal PHP session:
  582. </para>
  583. <example id="zend.service.windowsazure.storage.table.api.sessionhandler-usage">
  584. <title>Using table storage session handler</title>
  585. <programlisting language="php"><![CDATA[
  586. $storageClient = new Zend_Service_WindowsAzure_Storage_Table(
  587. 'table.core.windows.net', 'myaccount', 'myauthkey'
  588. );
  589. $sessionHandler = new Zend_Service_WindowsAzure_SessionHandler(
  590. $storageClient , 'sessionstable'
  591. );
  592. $sessionHandler->register();
  593. session_start();
  594. if (!isset($_SESSION['firstVisit'])) {
  595. $_SESSION['firstVisit'] = time();
  596. }
  597. // ...
  598. ]]></programlisting>
  599. </example>
  600. <warning>
  601. <para>
  602. The <classname>Zend_Service_WindowsAzure_SessionHandler</classname> session handler
  603. should be registered before a call to <functionname>session_start()</functionname>
  604. is made!
  605. </para>
  606. </warning>
  607. </sect2>
  608. </sect1>