Download the PHP package nargor/tiktok-live-connector-php without Composer

On this page you can find all versions of the php package nargor/tiktok-live-connector-php. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package tiktok-live-connector-php

tiktok-live-connector-php

A PHP library to receive TikTok LIVE stream events such as chat comments, gifts, and likes in realtime by connecting to TikTok's internal Webcast push service. This package is a PHP port of the Node.js library tiktok-live-connector. You only need a TikTok username (@uniqueId) โ€” no credentials required to connect to public streams.

๐Ÿ‡น๐Ÿ‡ญ เธญเนˆเธฒเธ™เธ เธฒเธฉเธฒเน„เธ—เธข: USAGE.md

[!NOTE] This is not a production-ready API. It is a reverse-engineering project that depends on TikTok's internal Webcast push service and on the EulerStream third-party sign server. For production use, prefer EulerStream's WebSocket API.

[!WARNING] The free EulerStream tier is heavily rate-limited. Set SIGN_API_KEY (see Signing Configuration) for any real use.

Other language ports

Table of Contents

Getting Started

  1. Install the package via Composer

Requires PHP 8.2+ with extensions: ext-json, ext-mbstring, ext-zlib, ext-sockets.

Platform support

OS Status Notes
Linux โœ… Fully supported ext-pcntl recommended for graceful Ctrl+C in CLI scripts.
macOS โœ… Fully supported Same as Linux.
Windows 10 / 11 โœ… Fully supported pcntl is not available; sapi_windows_set_ctrl_handler is used instead. Make sure extension=sockets is enabled in php.ini โ€” it ships with PHP for Windows but is sometimes commented out.

The library code itself contains no OS-specific calls. Only the example CLI in examples/chat-reader.php does graceful-shutdown signal wiring, and it auto-detects the platform.

  1. Create your first TikTok LIVE chat connection

Params and Options

To create a new TikTokLiveConnection object the following parameters can be specified.

new TikTokLiveConnection(string $uniqueId, ?LoopInterface $loop = null, array $options = [])

Param Required Description
uniqueId Yes The unique username of the broadcaster. You can find this in the URL.
Example: https://www.tiktok.com/@officialgeilegisela/live โ†’ officialgeilegisela
loop No A ReactPHP LoopInterface. Defaults to Loop::get().
options No Optional connection properties (see table below).

Available options

Option Default Description
sessionId null TikTok account session ID (from the sessionid cookie). Required for authenticated actions.
ttTargetIdc null The tt-target-idc cookie โ€” the datacenter the account is registered in. Required when sessionId is set.
signApiKey null EulerStream API key. If null, falls back to the SIGN_API_KEY env var, then to the free tier.
disableEulerFallbacks false Disable the EulerStream fallback used when HTML/API scraping fails to resolve room id.
fetchRoomInfoOnConnect true Fetch room info on connect(). Prevents connection to offline rooms.
connectWithUniqueId false Let EulerStream resolve the room id from uniqueId directly (skips local scraping). Useful for low-quality IPs that get captcha'd.
processInitialData true Emit events for the chat history bundled with the sign response. The WebSocket usually replays the same history on connect, so set this to false if you only want realtime events.

Example with options

Methods

Method Status Description
connect(?string $roomId = null): PromiseInterface โœ… Implemented Connect to the live stream. Returns a promise that resolves once the WebSocket is open. Optionally accepts an explicit roomId.
disconnect(): void โœ… Implemented Close the WebSocket and reset state.
isConnected(): bool โœ… Implemented Whether the WebSocket is currently open.
on(string $event, callable $listener): void โœ… Implemented Register an event listener (from evenement/evenement).
sendMessage(string $content) โŒ Not yet Send a chat message. Requires authenticated WebSocket + premium EulerStream signing.
fetchRoomInfo() โŒ Not yet Standalone room-info fetch. Currently only happens automatically during connect() when fetchRoomInfoOnConnect is true.
fetchAvailableGifts() โŒ Not yet List all available gifts.
fetchIsLive() โŒ Not yet Check whether the user is currently streaming.
waitUntilLive() โŒ Not yet Block until the user goes live.

The unimplemented methods can be added on top of the existing route classes in src/Http/Routes/. PRs welcome.

Properties

Property Description
webClient: WebClient HTTP client used for the pre-connect work (scrape + EulerStream calls).
wsClient: TikTokWsClient \| null The WebSocket client, populated after connect().
options: array Resolved options array (defaults + caller overrides).
roomId: string \| null The current room ID. null before connect.
uniqueId: string (readonly) The normalized username.
loop: LoopInterface (readonly) The ReactPHP event loop instance.

Signing Configuration

TikTok requires WebSocket URLs to be cryptographically signed. The signing algorithm lives in TikTok's obfuscated webmssdk.js and changes regularly, so all rewrites (Node, Python, Java, โ€ฆ) delegate this step to a third-party sign server. We use EulerStream by default โ€” the same as the Node lib.

Use the free tier (no key)

This works for small experiments but is rate-limited (~10 connections per day on a shared IP).

Use an API key

Sign up at https://www.eulerstream.com โ†’ Dashboard โ†’ API Keys โ†’ Create.

Then either:

Self-host a sign server

You can point at any EulerStream-compatible endpoint by setting the SIGN_API_URL env var:

Events

A TikTokLiveConnection extends Evenement\EventEmitter. Attach listeners with $connection->on(EVENT_NAME, callable).

Control Events

Constant Event name Fired when
WebcastEvent::CONNECTED connected WebSocket handshake completed.
WebcastEvent::DISCONNECTED disconnected WebSocket closed (any reason).
WebcastEvent::ERROR error Any unhandled internal error.
WebcastEvent::RAW_MESSAGE rawMessage Every inner protobuf message โ€” including ones we don't decode natively.

connected

disconnected

You can re-call connect() to reconnect. Wait a few seconds first to avoid being rate-limited.

error

rawMessage

Useful for decoding message types that aren't yet supported natively.

Message Events

Implemented

Constant Event name Payload
WebcastEvent::CHAT chat ['comment' => string, 'user' => ['userId', 'nickname', 'uniqueId']]
WebcastEvent::GIFT gift ['giftId' => int, 'repeatCount' => int, 'repeatEnd' => int, 'user' => [...]]
WebcastEvent::LIKE like ['likeCount' => int, 'totalLikeCount' => int, 'user' => [...]]
chat

Triggered when a viewer posts a chat comment.

gift

Triggered when a viewer sends a gift.

NOTE: Users can send gifts in a streak. Each tick of the streak fires another gift event with an increasing repeatCount. After the streak ends, one final event fires with repeatEnd == 1. Even a single, non-streak gift fires twice: once with repeatEnd == 0 and once with repeatEnd == 1. Handle accordingly:

like

Triggered when a viewer sends likes. For high-traffic streams TikTok does not always emit this.

Not yet implemented

The following events from the Node lib are not yet decoded. Their raw bytes still arrive via WebcastEvent::RAW_MESSAGE, so you can extend src/Protobuf/Codec.php and TikTokLiveConnection::dispatchInner() to add support. PRs welcome.

member (join), social (follow/share), subscribe, envelope (treasure box), questionNew, linkMicBattle, linkMicArmies, liveIntro, roomUser (viewer count), emote, goalUpdate, roomMessage, captionMessage, imDelete, inRoomBanner, rankUpdate, pollMessage, rankText, linkMicBattlePunishFinish, linkMicBattleTask, linkMicFanTicketMethod, linkMicMethod, unauthorizedMember, oecLiveShopping, msgDetect, linkMessage, roomVerify, linkLayer, roomPin, streamEnd.

Examples

Minimal chat reader

The simplest possible script โ€” see examples/chat-reader.php for the full version with signal handling.

Reconnect on disconnect

Save chat to a log file

Save events to MySQL

Forward to a webhook

Live dashboard counter

Authenticated connection (TikTok account session)

You can supply your account's sessionid + tt-target-idc cookies for authenticated WebSocket features (matches the Node lib's sessionId option). Extract them from your browser's DevTools after logging into https://www.tiktok.com.

[!CAUTION] The session id is a credential. Keep it out of source control and treat it like a password. The WebSocket connection is signed by EulerStream (a third party) โ€” only enable authenticated mode if you trust the sign server.

Architecture

Limitations vs. the Node lib

  1. No sendMessage() โ€” requires authenticated WebSocket + premium EulerStream signing.
  2. Sync HTTP for pre-connect โ€” fine for a daemon, not ideal for high-concurrency reuse.
  3. No proxy support yet โ€” Guzzle and Pawl both support proxies; not wired through here.
  4. MVP event coverage โ€” only chat / gift / like are decoded. Use RAW_MESSAGE for everything else.
  5. Schema drift โ€” TikTok occasionally changes protobuf field numbers. If decoding breaks for a message you care about, compare against the Node lib's tiktok-schema.js and update the field tags in Codec.php.

Contributors

License

MIT โ€” same as the upstream Node lib. See LICENSE.


All versions of tiktok-live-connector-php with dependencies

PHP Build Version
Package Version
Requires php Version >=8.2
ext-json Version *
ext-mbstring Version *
ext-zlib Version *
ext-sockets Version *
guzzlehttp/guzzle Version ^7.8
ratchet/pawl Version ^0.4.1
react/event-loop Version ^1.5
react/promise Version ^3.1
evenement/evenement Version ^3.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package nargor/tiktok-live-connector-php contains the following files

Loading the files please wait ...