PHPackages                             greatcode/otp-reader - 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. greatcode/otp-reader

ActiveLibrary

greatcode/otp-reader
====================

OTP Reader - Thread-safe, atomic, file-based Google OAuth credential storage library in native PHP with Mail Reader &amp; Gmail Driver

v0.0.2(today)01↑2900%MITPHPPHP &gt;=8.1CI passing

Since Jul 30Pushed todayCompare

[ Source](https://github.com/gcteamsource/otp-reader)[ Packagist](https://packagist.org/packages/greatcode/otp-reader)[ RSS](/packages/greatcode-otp-reader/feed)WikiDiscussions main Synced today

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

GreatCode OTP Reader &amp; Google OAuth Manager
===============================================

[](#greatcode-otp-reader--google-oauth-manager)

[![PHP Version](https://camo.githubusercontent.com/35a3bdb1bce06d7a3dbf9e85884c3825a7ae0a352825e3e64ecc741b9d690087/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d253345253344382e312d3838393242462e7376673f7374796c653d666c61742d737175617265)](https://php.net/)[![License: MIT](https://camo.githubusercontent.com/1b01ef0024ba0866c115986b895301f657c1b21fc29f05c4844b7f2e8d89204d/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d4d49542d79656c6c6f772e7376673f7374796c653d666c61742d737175617265)](LICENSE)[![PSR-12](https://camo.githubusercontent.com/2f46a0c42c968287ebccb87389ea7955d2f224f46d43f39a92b779af5a105b90/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5053522d31322d636f6d706c69616e742d626c75652e7376673f7374796c653d666c61742d737175617265)](https://www.php-fig.org/psr/psr-12/)[![Strict Types](https://camo.githubusercontent.com/bdc968cf53ea616d1a0de9cba5e6df960b95c6f70523f979508078b35ddf6a08/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5374726963745f54797065732d3130302532352d677265656e2e7376673f7374796c653d666c61742d737175617265)](src/)

An enterprise-grade, thread-safe, native PHP library designed for **automated mail reading, OTP code extraction in web scraping, and atomic Google OAuth credential management**.

Engineered specifically for high-concurrency production environments (PHP-FPM, Docker Replicas, Multi-Worker Scraping Pipelines) on shared Linux filesystems without requiring database dependencies.

---

🌟 Key Features
--------------

[](#-key-features)

- **🔒 Thread-Safe &amp; Race-Condition Proof:** Uses `flock(LOCK_EX)` on persistent `.lock` files to prevent concurrent workers or containers from triggering duplicate token refreshes simultaneously.
- **⚡ Atomic Storage:** File writes use temporary file buffering (`.tmp` -&gt; `fflush()` -&gt; `rename()`), ensuring JSON files are never corrupted even during sudden process termination or power loss.
- **🛡️ Automated Corruption Recovery:** Automatically recovers stored credentials from `.bak` backup files if primary JSON files are corrupted.
- **📧 Gmail REST API v1 Driver:** Native cURL HTTP transport wrapper for Gmail API—no heavy SDK dependencies required.
- **🔑 Automatic OTP Extraction:** Built-in heuristic engine for extracting 4–8 digit or alphanumeric verification codes from both English and Indonesian email payloads.
- **⏱️ Smart Polling Retry &amp; Delay:** Retries message polling with customizable attempt limits and delay intervals until the email arrives.
- **📫 Auto Mark-as-Read:** Automatically marks processed emails as `READ` upon successfully retrieving OTP codes to prevent re-reading stale messages.
- **🎨 Glassmorphism Web UI:** Includes a single-line Web Registration handler (`MailReader::handleRegistration()`) with a responsive, modern HTML interface.
- **0️⃣ Zero Framework Dependencies:** Written in pure, strict-typed PHP 8.1+ under the `Greatcode\OtpReader\` namespace adhering to PSR-12 standard.

---

🏗️ Architecture Overview
------------------------

[](#️-architecture-overview)

 ```
graph TD
    A["Scraping Script / Web App"] --> B["Greatcode\OtpReader\Mail\MailReader Facade"]
    B --> C["Greatcode\OtpReader\Mail\Drivers\GmailDriver"]
    C --> D["Greatcode\OtpReader\Google\CredentialManager"]
    D --> E["Greatcode\OtpReader\Google\CredentialLock (flock LOCK_EX)"]
    D --> F["Greatcode\OtpReader\Google\CredentialStorage"]
    F --> G[("JSON Filesystem /storage/google/")]
    C --> H["Gmail REST API v1"]
```

      Loading ---

📦 Installation
--------------

[](#-installation)

Install via Composer:

```
composer require greatcode/otp-reader
```

---

🚀 Quick Start Guide
-------------------

[](#-quick-start-guide)

### 1. Read OTP for Web Scraping Scripts (1-Line Initialization)

[](#1-read-otp-for-web-scraping-scripts-1-line-initialization)

```
