PHPackages                             thedoctor0/psonic - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Search &amp; Filtering](/categories/search)
4. /
5. thedoctor0/psonic

ActiveLibrary[Search &amp; Filtering](/categories/search)

thedoctor0/psonic
=================

PHP client for Sonic Search Engine

1.0.0(1y ago)081MITPHPPHP &gt;=8.0

Since Jun 2Pushed 1y agoCompare

[ Source](https://github.com/TheDoctor0/psonic)[ Packagist](https://packagist.org/packages/thedoctor0/psonic)[ RSS](/packages/thedoctor0-psonic/feed)WikiDiscussions master Synced today

READMEChangelog (1)Dependencies (1)Versions (2)Used By (0)

Psonic - PHP client for sonic auto suggestion engine
====================================================

[](#psonic---php-client-for-sonic-auto-suggestion-engine)

[![codecov](https://camo.githubusercontent.com/f32bf1e0de6a320b1c8f8d13c8cba25f11f7e76d87388a7909b645406a3c4d5e/68747470733a2f2f636f6465636f762e696f2f6769746875622f707073686f62692f70736f6e69632f6272616e63682f6d61737465722f67726170682f62616467652e7376673f746f6b656e3d79367939505678446367)](https://codecov.io/github/ppshobi/psonic)

[![.github/workflows/tests.yml](https://github.com/ppshobi/psonic/actions/workflows/tests.yml/badge.svg)](https://github.com/ppshobi/psonic/actions/workflows/tests.yml)

Summary
-------

[](#summary)

[Sonic](https://github.com/valeriansaliou/sonic) is a super fast auto-suggestion engine built by the team at [crisp.chat](crisp.chat), a customer engagement platform. it is built in Rust and they officially support a javascript client, but if you want to use sonic via PHP, this is the library that you can look for. Completely unit tested, and adheres to modern coding standards, and offers a clean API to interact with sonic.

Installation &amp; Usage
------------------------

[](#installation--usage)

you need a running sonic instance (locally or in the cloud, the port 1491 should be accessible) php7+ and composer to make this library work. [Read more on installing sonic](https://github.com/valeriansaliou/sonic/blob/master/README.md)

- goto your project directory
- execute `composer require ppshobi/psonic`once the installation is completed you should be able to use the library as follows

Api Documentaion
----------------

[](#api-documentaion)

[Full API Documentaion](api-docs.md)

Usage
-----

[](#usage)

once you have psonic in place, you have access to the `Client` and `Channel` classes, Each channel instance requires a separate new client instance since sonic doesn't allow channel switching within the same connection. Read more about sonic concepts below

### Indexing

[](#indexing)

To index few objects into the sonic use the following sample code, make sure you have a running instance of sonic on port 1491

```
$ingest  = new Psonic\Ingest(new Psonic\Client('localhost', 1491, 30));
$control = new Psonic\Control(new Psonic\Client('localhost', 1491, 30));
$ingest->connect('SecretPassword1');
$control->connect('SecretPassword1');
echo $ingest->push('messagesCollection', 'defaultBucket', "1234","hi Shobi how are you?")->getStatus(); // OK
echo $ingest->push('messagesCollection', 'defaultBucket', "1235","hi are you fine ?")->getStatus(); //OK
echo $ingest->push('messagesCollection', 'defaultBucket', "1236","Jomit? How are you?")->getStatus(); //OK

echo $control->consolidate(); // saves the data to disk

$ingest->disconnect();
$control->disconnect();
```

### Searching/AutoSuggestions

[](#searchingautosuggestions)

To search on the index using the following sample code

```
$search = new Psonic\Search(new Psonic\Client('localhost', 1491, 30));
$search->connect('SecretPassword1');
var_dump($search->query('messagesCollection', 'defaultBucket', "are")); // you should be getting an array of object keys which matched with the term "are"
$search->disconnect();
```

To get autosuggestions/autocomplete for a term from the index use the following sample code

```
$search = new Psonic\Search(new Psonic\Client('localhost', 1491, 30));
$search->connect('SecretPassword1');
var_dump($search->suggest('messagesCollection', 'defaultBucket', "sho")); // you should be getting an array of terms which matched the term "sho". Considering previous example and it should output "shobi"
$search->disconnect();
```

Basic sonic Concepts
--------------------

[](#basic-sonic-concepts)

Sonic is more of an `identifier index` than a `document index`. Meaning, if the query matches some records it will be giving you the identifier of the matched object, than the object itself. Probably you will have to query the actual data store again with those keys. Check Basic Terminology used in sonic below as well. [Read more on sonic repository](https://github.com/valeriansaliou/sonic/blob/master/README.md)

### Channels

[](#channels)

Sonic doesn't offer an HTTP endpoint as of now, rather it offers a TCP endpoint like Redis (They call it RESP protocol), and we call it channel. There are 3 kind of channels

- **Ingest** (Typically offers data indexing (index), deindexing (pop) and flushing operations)
- **Search** (Offers Query and Suggest operations)
- **Control** (Offers the collection control operations such as data consolidation)

### Basic Terminology

[](#basic-terminology)

Consider you are storing the chats of your customers from an e-commerce website.

- `collection` - which contains all your messages/products etc...
- `bucket` - you might need to store messages specific to a user so that a collection can contain one or more user buckets, so the search can be more specific, or according to your use case, you can put all your messages in one bucket itself and name it `default` or `generic` etc..
- `object` - The object is the key of the actual data that you have in the database, usually, the object key will be an identifier/primary\_key from the source of truth, as the primary key from the messages table, this will be returned when you query matches some records from the sonic index.
- `terms` - This is the actual text data you save in the sonic. Read more on the sonic documentation

Testing &amp; Contribution
--------------------------

[](#testing--contribution)

To run sonic in local, the best way is to use `docker`

Run below command in terminal. you should have a sonic instance running.

`$ docker run -d -p 1491:1491 -v /path/to/sonic.cfg:/etc/sonic.cfg -v /path/to/sonic/data/store:/var/lib/sonic/store/ valeriansaliou/sonic:v1.1.9`

Then do a git clone of this project

`$ cd ~ && git clone https://github.com/ppshobi/psonic.git`

then `cd` into the project directory and do a composer install

`$ cd psonic && composer install`

Use `phpunit` to run tests.

Feel free to send pull requests.
--------------------------------

[](#feel-free-to-send-pull-requests)

###  Health Score

29

—

LowBetter than 57% of packages

Maintenance47

Moderate activity, may be stable

Popularity9

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity42

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 88.9% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

397d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/16612504?v=4)[Dawid Janik](/maintainers/TheDoctor0)[@TheDoctor0](https://github.com/TheDoctor0)

---

Top Contributors

[![ppshobi](https://avatars.githubusercontent.com/u/8536607?v=4)](https://github.com/ppshobi "ppshobi (120 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (6 commits)")[![TheDoctor0](https://avatars.githubusercontent.com/u/16612504?v=4)](https://github.com/TheDoctor0 "TheDoctor0 (3 commits)")[![manavo](https://avatars.githubusercontent.com/u/259487?v=4)](https://github.com/manavo "manavo (2 commits)")[![skluck](https://avatars.githubusercontent.com/u/3161125?v=4)](https://github.com/skluck "skluck (2 commits)")[![forgetmiss](https://avatars.githubusercontent.com/u/103432535?v=4)](https://github.com/forgetmiss "forgetmiss (1 commits)")[![lens0021](https://avatars.githubusercontent.com/u/28209361?v=4)](https://github.com/lens0021 "lens0021 (1 commits)")

---

Tags

search enginesonicauto suggestionpsonic

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/thedoctor0-psonic/health.svg)

```
[![Health](https://phpackages.com/badges/thedoctor0-psonic/health.svg)](https://phpackages.com/packages/thedoctor0-psonic)
```

###  Alternatives

[ppshobi/psonic

PHP client for Sonic Search Engine

134105.0k3](/packages/ppshobi-psonic)[serps/core

Search engine scrapper

96167.2k8](/packages/serps-core)[hightman/xunsearch

xunsearch php sdk, include yii, yii2 supports

88114.5k11](/packages/hightman-xunsearch)[nilportugues/sphinx-search

Fully unit tested SphinxClient (SphinxAPI) for PHP5.3 and above to be used with SphinxSearch

24458.5k2](/packages/nilportugues-sphinx-search)[opensearchserver/opensearchserver

PHP library for OpenSearchServer: professionnal search engine, crawlers (web, file, database), REST APIs, .... This library uses OpenSearchServer's V2 API.

4768.0k](/packages/opensearchserver-opensearchserver)[ripaclub/sphinxsearch

Sphinx Search library provides SphinxQL indexing and searching features

6232.3k3](/packages/ripaclub-sphinxsearch)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
