PHP guide
This page walks through the whole PHP SDK in the order you would use it. Each step starts with the shortest code that works.
Download the PHP SDK if you have not done so yet.
Requirements
Without curl, the SDK uses PHP streams. On Linux and macOS, pass your own systemId and storage when you create the client, as shown in Options.
Add the SDK to your project
Unzip the download into a folder in your project, for example authlyx, and include its autoloader:
With Composer, add the folder as a path repository and require authlyx/authlyx:
Create the client
The first value is your app’s AppKey. Find it in the dashboard under your application’s credentials. The second is the version of the program you are building. AuthlyX compares it with the versions you allow in the dashboard, so raise it each time you ship a new build. See Allowed Versions.
On PHP 8 you can name the arguments:
Create one client for the whole script.
How calls work
Every call waits for the reply and returns a Result with ok, code, message and data. initialize() always returns a result, even without internet. Other calls throw AuthlyXException when AuthlyX refuses or cannot be reached:
Start the SDK
initialize() connects to AuthlyX, checks that this version is allowed and loads your app’s settings. It must succeed before anything else. init() is the same call.
Sign in
These are three ways to sign in. Use the one that matches the access type you created in the dashboard. login with one value signs in with a license key. Device login signs in the current Windows user with no form, and only works for devices you approved first; see Device login.
Create an account, change the password, add time
registerUser creates the account with a license and signs it in. redeemLicense adds a license’s time to the signed-in account.
Read the account
userData works as an object or an array. It is empty until someone signs in. $app->userData->toArray() returns every field. The fields are listed in User Data.
Features and metadata
Features come from the plan and the account. Some are on/off, some carry a value such as "high" or 90. Metadata is extra information attached to accounts. See Features and metadata.
getFeatures lists every feature and getFeature returns one. For metadata, use getAllMetadata, getMetadata and checkMetadata.
Save metadata
The value can be text, a number, a boolean or an array.
Cloud variables
For getVariable, data is the value itself. See Cloud variables.
Scripts
The second value is an optional revision. The SDK checks the script’s signature before returning it. It does not run the script. See Scripts.
Logs and webhooks
Staying signed in
PHP has no background threads. With the default server heartbeat, the SDK checks the session before a call once the interval set by the server has passed, and refreshes features and metadata each time. If you ban, pause or expire the account, that check ends the session.
In a long-running script, call $app->heartbeat() from your loop. It only contacts AuthlyX when a check is due, and returns null otherwise. To check right away, call $app->checkSession(); $app->onResume() does the same.
To be told when the session ends or the connection changes, pass functions when you create the client:
onConnection receives online, disconnected, untrusted or disposed. More in Sessions and heartbeats.
Offline access
Later, without internet, initialize() succeeds with OFFLINE_MODE, and the user signs in with the same license key or username and password. The SDK checks them against the saved permit and the sign-in succeeds with the code OFFLINE_ACCESS. $app->hasOfflineAccess() tells you whether this PC has a valid saved permit. Signing out deletes it. See Offline access.
Updates
When this version is not allowed, initialize() fails with UPDATE_REQUIRED or VERSION_MISMATCH. Read the details from the result:
On Windows with ffi, pass 'updatePrompt' => true to show the Windows update box with a button that opens your download page. See Automatic updates.
Sign out and shut down
logout ends the session, clears userData and deletes saved offline access on this PC, even when AuthlyX cannot be reached. close releases the client; a closed client cannot be used again.
Results and errors
AuthlyXException has getErrorCode(), getMessage(), getKind(), getStatus() and getRequestId(). getKind() is server, network, security or storage. network means the SDK could not reach AuthlyX or confirm the answer; do not treat it as a ban. All codes are listed in Errors.
Options
The third argument is an array of options. Every option is optional on Windows.
On Linux, for example:
FileStore writes files readable only by the current user. MemoryStore keeps nothing after the script ends. You can also implement AuthlyX\Storage\Store with your own protected storage.
A complete program
The example on GitHub is a fuller console app with a menu for every feature. Each method also has its own page with every language side by side under SDK methods.

