Skip to content

Commit

Permalink
chore: add PHP SDK storage examples
Browse files Browse the repository at this point in the history
  • Loading branch information
pgautier404 committed Jul 17, 2024
1 parent b102e0c commit 09d6059
Show file tree
Hide file tree
Showing 5 changed files with 236 additions and 209 deletions.
1 change: 1 addition & 0 deletions docs/sdks/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,7 @@ Momento server-side SDKs allow you to take advantage of Momento's low-latency Ca
}}>
<LinkButton text="Overview" link="/sdks/php"/>
<LinkButton text="Cache" link="/sdks/php/cache.html"/>
<LinkButton text="Storage" link="/sdks/php/storage.html"/>
<LinkButton text="Examples" link="https://github.com/momentohq/client-sdk-php/blob/main/examples" openInNewTab="true" />
<LinkButton text="Packages" link="https://packagist.org/packages/momentohq/client-sdk-php" openInNewTab="true" />
<LinkButton text="Source Code" link="https://github.com/momentohq/client-sdk-php" openInNewTab="true" />
Expand Down
2 changes: 1 addition & 1 deletion docs/sdks/php/cache.md → docs/sdks/php/cache.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ Add our repository to your `composer.json` file and our SDK as a dependency:
```json
{
"require": {
"momentohq/client-sdk-php": "1.7.1"
"momentohq/client-sdk-php": "1.11.1"
}
}
```
Expand Down
6 changes: 6 additions & 0 deletions docs/sdks/php/index.md → docs/sdks/php/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ keywords:
- event-driven architecture
- redis
- serverless
- storage
- persistence
- datastore
- database
- duarble
- sdk
- sdks
- api
Expand Down Expand Up @@ -43,6 +48,7 @@ The source code can be found on GitHub: [momentohq/client-sdk-php](https://githu
## Resources

- [Getting started with Momento Cache in PHP](/sdks/php/cache)
- [Getting started with Momento Storage in PHP](/sdks/php/storage)
- [PHP SDK examples](https://github.com/momentohq/client-sdk-php/blob/main/examples/README.md): working example projects that illustrate how to use the PHP SDK

## Integrations
Expand Down
105 changes: 105 additions & 0 deletions docs/sdks/php/storage.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
---
sidebar_position: 2
sidebar_label: Storage
title: Getting started with Momento Storage in PHP
description: Learn the basic building blocks for writing PHP code to interact with Momento Storage.
keywords:
- momento
- cache
- caching
- topics
- pubsub
- pub/sub
- eda
- event-driven architecture
- redis
- serverless
- storage
- persistence
- datastore
- database
- duarble
- sdk
- sdks
- api
- examples
- resources
- getting started
- quick start
- server-side
- php
- laravel
- drupal
---

import { SdkExampleCodeBlock } from "@site/src/components/SdkExampleCodeBlock";
// This import is necessary even though it looks like it's un-used; The inject-example-code-snippet
// plugin will transform instances of SdkExampleCodeBlock to SdkExampleCodeBlockImpl
import { SdkExampleCodeBlockImpl } from "@site/src/components/SdkExampleCodeBlockImpl";

# Getting Started with Momento Storage in PHP

If you need to get going quickly with PHP and Momento Storage, this page contains the basic API calls you'll need.

For more info, you can also see [the PHP SDK on GitHub](https://github.com/momentohq/client-sdk-php).

### Prerequisites

* A Momento API Key is required. You can generate one using [the Momento console](https://console.gomomento.com/).
* Installation of PHP 8.0 or higher
* Installation of the [gRPC PHP extension](https://github.com/grpc/grpc/blob/master/src/php/README.md).
* Installation of the [protobuf C extension](https://developers.google.com/google-ads/api/docs/client-libs/php/protobuf#c_implementation)
* Installation of [Composer](https://getcomposer.org/doc/00-intro.md) - A common library and dependency manager for PHP.

### Configure composer to get the PHP SDK

Add our repository to your `composer.json` file and our SDK as a dependency:

```json
{
"require": {
"momentohq/client-sdk-php": "1.11.1"
}
}
```

Run `composer update` to install the necessary prerequisites.

## Import libraries and connect to return a StorageClient object

This code sets up the main function, pulls in the necessary imports, and instantiates the StorageClient that will be used to interact with your store.

<SdkExampleCodeBlock language={'php'} file={'storage-cheat-sheet.php'} />

## Create a new store in Momento Storage
Use this function to create a new store in your account.

<SdkExampleCodeBlock language={'php'} snippetId={'API_Storage_CreateStore'} />

## List the names of existing stores in your account
A simple list of the names of stores for the account.

<SdkExampleCodeBlock language={'php'} snippetId={'API_Storage_ListStores'} />

## Write an item to a store
A simple example of doing a put operation.

<SdkExampleCodeBlock language={'php'} snippetId={'API_Storage_Put'} />

## Read an item from a store
This is an example of a simple read operation to get an item from a sore.

<SdkExampleCodeBlock language={'php'} snippetId={'API_Storage_Get'} />

## Delete an item from a store
This is an example of a simple delete operation to remove an item from a store.

<SdkExampleCodeBlock language={'php'} snippetId={'API_Storage_Delete'} />

## Running the code

You can find complete, working examples in the [PHP SDK GitHub repo examples directory](https://github.com/momentohq/client-sdk-php/blob/main/examples).

:::info
Beyond these basic API calls check out the [API reference page](/storage/develop/api-reference/index.mdx) for more information on the full assortment of Momento API calls.
:::
Loading

0 comments on commit 09d6059

Please sign in to comment.