Initialize the PHP API client
Before you can index your data or search your Algolia indices, you must initialize a search client with your application ID and API key. You can find both in your Algolia account.
We released a new version of the PHP API client in public beta. Read the beta documentation for more information.
Initialize the search client
The search client handles authentication and lets you manage your indices, for example, add data to them, or search them.
1 2 3 4 5 6 7 8 9 10 11 // composer autoload require __DIR__ . '/vendor/autoload.php'; // if you aren't using composer // require_once 'path/to/algolia/folder/autoload.php'; use Algolia\AlgoliaSearch\SearchClient; $client = SearchClient::create('YourApplicationID', 'YourWriteAPIKey'); $index = $client->initIndex('your_index_name');
your_index_name with the name of the index you want to use. You can find your existing indices in the Algolia dashboard or using the
listIndices method. If the index doesn’t exist, a new, empty index is created locally. It’s created on Algolia’s servers only if you add records to the index.
Don’t use sensitive or personally identifiable information as your index name, including usernames, IDs, or email addresses. Index names are publicly shared.
Operations that are scoped to your Algolia application through the
Operations scoped to an
The Recommend, Personalization, Insights, and A/B testing APIs come with their own clients: