CI4 for Perfex CRM By Head Random • 2026-11-26 11:00 AM

Strangler Fig Architecture: How IgniteCore Bridges CI3 and CI4 in Perfex CRM

235.04 ms

IgniteCore modernizes Perfex CRM using a Strangler Fig Pre-Boot Front-Dispatcher that routes selected URLs to an embedded CodeIgniter 4.7.6 kernel while leaving stock CodeIgniter 3.1.11 completely intact for legacy modules. By isolating both kernels into mutually exclusive PHP lifecycles connected through 7 shared-state bridges and 6 route filters, it eliminates all 13 constant collisions, 89 global function collisions, and App_Controller version locks with zero core file edits.

Technology Stack Comparison: CI3 Legacy vs Standalone CI4 vs IgniteCore

Upgrading Perfex CRM is difficult because CodeIgniter 3 and CodeIgniter 4 share almost no runtime primitives despite carrying the same brand name.

Strangler Fig Matrix
Technology Layer
Perfex CRM CI3 (3.1.11)
CI3 3.1.11
Standalone CI4 Framework
Standalone CI4
IgniteCore Dual-Kernel Bridge Zero Core Mutation
CI4 4.7.6 + CI3 Fallback
Code Organization Global class namespace; manual require_once and $this->load-> PSR-4 namespaces, strict autoloading, typed services PSR-4 namespaces in modules/{slug}/ignite/ alongside CI3 legacy modules
Cross-Cutting Pipeline hooks()-> global actions (918 hook names across core/modules) HTTP Route Filters (FilterInterface) & Event Dispatcher 6 Perfex-aware CI4 Filters + PerfexEventOutboxService hook relay
Dependency Delivery Legacy bundled libs; no modern package structure Requires composer install & external vendor/ tree Zero-Vendor CI4 4.7.6 inside runtime/system/ThirdParty/ (upload-ready ZIP)
PHP Runtime Support Official EOL at PHP 8.1; PHP 8.2-8.4 triggers dynamic property errors Native PHP 8.2 / 8.3 / 8.4 typed support CI4 4.7.6 runs natively on PHP 8.2-8.4 while CI3 stays untouched on legacy routes
Upgrade & Core Safety Direct core edits break on Perfex auto-updates Replaces Perfex entirely; loses 54+ CodeCanyon modules Zero Core Mutation; survives Perfex auto-updates and supports Safe Mode fallback
flowchart TD
    REQ["Incoming HTTP Request"] --> ENTRY["Entry Point (.htaccess Block or 3-Line index.php Marker)"]
    ENTRY --> DISP["Pre-Boot Front-Dispatcher (< 0.5ms Pure PHP)"]
    DISP --> CB{"5-Layer Circuit Breaker<br/>PHP >= 8.2, intl/mbstring,<br/>Enabled Flag, Manifest, No Fallback"}
    CB -->|"Fail or Unmatched Route"| CI3["Stock Perfex CRM CI3 (index.php Fallback)"]
    CB -->|"Pass"| MAN["OPcache route_manifest.php Match"]
    MAN -->|"Unmatched or Disabled"| CI3
    MAN -->|"Matched & Enabled"| CI4["Pure CodeIgniter 4.7.6 Runtime (Zero-Vendor)"]
    CI4 --> FILT["Route Filters (perfexCsrf, staffAuth, staffCan, sessionReadOnly)"]
    FILT --> BRIDGES["7 Shared Bridges (Config, DB/File Session, Options, Auth, Lang, Outbox)"]
    BRIDGES --> DB[("Shared Perfex MySQL (tblsessions, tblstaff_permissions, tbloptions)")]
    CI3 --> DB

Why Mutually Exclusive Pre-Boot Dispatch Beats In-Process Wrapping

A common misconception when bridging two PHP frameworks is attempting to boot CodeIgniter 4 inside a CodeIgniter 3 controller or module hook. In Perfex CRM, in-process kernel wrapping fails immediately for three hard technical reasons verified by static codebase analysis:

  1. 13 Global Constant Collisions: Both CI3 and CI4 define identical global constants such as APPPATH, FCPATH, ENVIRONMENT, and EXIT_* status codes. PHP raises fatal redefinition errors or corrupts path resolution the moment the second kernel initializes.
  2. 89 Global Function Collisions: CI3 and CI4 share 89 global helper and core function signatures: 5 foundational functions in Common.php, 2 severely divergent core helpers (lang() and redirect()), and 82 global helper functions. Because PHP cannot unload or redefine global functions inside a single request, loading both kernels simultaneously guarantees fatal errors or silent signature mismatches.
  3. Hard App_Controller Version Check: Perfex's App_Controller.php explicitly validates CI_VERSION and calls die() if the running constant does not match '3.1.11'.

IgniteCore avoids every collision through Mutually Exclusive Pre-Boot Dispatch. Before either kernel boots, bootstrap/dispatcher.php checks an OPcache-compiled route_manifest.php and runs a 5-layer Circuit Breaker (PHP >= 8.2, intl/mbstring, enabled flag, valid manifest, no ?ignite_fallback=1 or Safe Mode). Only one kernel ever boots per HTTP request: CI4 4.7.6 handles matched modern routes, and stock CI3 handles everything else.

Zero-Vendor CI4 4.7.6 Delivery Inside runtime/system/ThirdParty/

Standard CodeIgniter 4 projects assume CLI access to Composer (composer create-project) and hundreds of nested vendor/ directories. Most Perfex CRM administrators deploy modules via the browser admin uploader (Setup > Modules) on shared hosting or CyberPanel without SSH Composer pipelines.

IgniteCore packages an unmodified CodeIgniter 4.7.6 runtime directly inside modules/ignite_core/runtime/ with bundled runtime/system/ThirdParty/ dependencies (Laminas\Escaper, PSR\Log, and Kint). Module developers and administrators get a zero-Composer, drop-in ZIP installation with full PSR-4 autoloading and Spark CLI support (ignite:doctor, ignite:manifest, ignite:entry, ignite:make-module).

Complete Walkthrough: The 7 Shared-State Bridges

Running two mutually exclusive kernels requires sharing state cleanly through MySQL and disk boundaries rather than shared PHP memory. IgniteCore implements 7 Shared-State Bridges:

Shared-State Bridge Underlying Mechanism Role in Dual-Kernel Parity
1. PerfexConfigBridge Reads application/config/app-config.php & database credentials Eliminates duplicate .env DB secrets; inherits encryption keys and base URLs automatically
2. PerfexDatabaseSessionHandler Raw tblsessions (idPrefix = '', INT(10) UNIX time()) + FileHandler Preserves 100% SSO parity whether Perfex uses MySQL or file-based sessions
3. PerfexOptionsService Reads/writes tbloptions with typed decoding Gives CI4 services instant access to Perfex settings (companyname, SMTP, custom module options)
4. PerfexAuthService Resolves active tblstaff / tblcontacts & tblstaff_permissions Powers staffAuth, staffCan, and clientAuth identically to Perfex core
5. PerfexLangService Bridges Perfex active language files into CI4 locale services Ensures consistent UI labels and error messages matching each user's CRM language
6. PerfexEventOutboxService Transactional queue in tblignite_core_event_outbox + Cron relay Relays CI4 domain events to CI3 hooks()->do_action() via after_cron_run (up to 50 events/run, retry cap < 5)
7. PerfexIncidentGuard Stack-trace attribution into module_incidents.json (max 100 entries) Classifies CI4 exceptions into 8 categories and triggers Auto-Quarantine (3 errors / 300s) back to CI3

PerfexEventOutboxService deserves special attention. Because CI3 hooks cannot be invoked inside a pure CI4 request without triggering the 89-function collision, CI4 controllers persist domain events transactionally into tblignite_core_event_outbox. Perfex's regular after_cron_run job processes batches of up to 50 pending events per run (with a strict retry cap < 5) inside the real CI3 process, executing downstream hooks()->do_action() listeners safely.

The 6 Route Filters Protecting Every CI4 Endpoint

Modules declare routes via modules/{slug}/ignite/manifest.php and compose IgniteCore's 6 Route Filters:

  1. perfexCsrf: Timing-safe hash_equals() validation matching csrf_cookie_name, csrf_token_name, and X-CSRF-TOKEN, regenerate = false for multi-tab safety, csrf_exclude_uris.php inheritance, and HTTP 419 AJAX responses.
  2. staffAuth: Verifies authenticated CRM staff session state before entering admin controllers.
  3. staffCan: Enforces granular tblstaff_permissions capability checks (e.g., staffCan:view,ignite_core).
  4. clientAuth: Verifies authenticated customer portal (tblcontacts) sessions for client-facing CI4 pages.
  5. apiAuth: Secures programmatic /ignite/api/v1/* endpoints with token and authorization validation.
  6. sessionReadOnly: Calls session_write_close() right after auth read so parallel AJAX requests never block on PHP session locks.

Zero Core Mutation & Forward Compatibility (CI4.8+ / CI5 / CI6)

IgniteCore never edits files inside Perfex's application/ or system/ folders. Even when administrators use the optional 3-line index.php marker mode (for Nginx/IIS hosts where .htaccess is ignored), IgniteCore preserves guarded *.orig.bak.php backups and handles Perfex auto-updates cleanly via a single click or php spark ignite:entry check.

Just as importantly, decoupling the runtime inside modules/ignite_core/runtime/ establishes a clean upgrade path beyond CodeIgniter 4.7.6. Because Dual-Mode modules depend only on the small ignite/manifest.php contract and standard PSR-4 interfaces rather than hardcoded CI3 globals, upgrading the embedded runtime to CI4.8+, CI5, or future CI6 requires updating IgniteCore's isolated runtime folder without rewriting downstream business modules.

Frequently Asked Questions

Why can't Perfex CRM simply boot CI4 inside a CI3 module controller?

Booting CI4 inside an active CI3 process collides immediately with 13 duplicate constants (APPPATH, FCPATH, ENVIRONMENT), 89 global function names (lang(), redirect(), Common.php), and App_Controller's strict CI_VERSION check. Pre-Boot Dispatch keeps the two kernels mutually exclusive per HTTP request.

How do CI4 controllers trigger legacy Perfex CI3 hooks safely?

CI4 controllers write events to tblignite_core_event_outbox via PerfexEventOutboxService. Perfex's native after_cron_run hook relays batches of up to 50 queued events per run (retry limit < 5) inside the CI3 process so legacy hooks()->do_action() listeners run safely.

What happens if a Perfex CRM auto-update overwrites the root index.php or .htaccess?

In .htaccess mode, Perfex updates rarely touch the managed Apache/OpenLiteSpeed rewrite block. If a core update replaces index.php in marker mode, the 5-Layer Circuit Breaker falls back gracefully to stock CI3 without crashing, and administrators can restore the 3-line entry marker in one click from Setup > IgniteCore or via php spark ignite:entry.

Does IgniteCore lock module developers into a proprietary framework?

No. Modules follow standard CodeIgniter 4.7.6 PSR-4 conventions paired with a lightweight ignite/manifest.php declaration. Business logic stays cleanly portable across future CI4.8+, CI5, and CI6 releases.

Related Guides

HeadRandom Perfex CRM Engineering

Need a Custom Perfex CRM Module, Bug Fix, or CodeIgniter 4 Upgrade?

Avoid broken updates, PHP 8.2-8.4 errors, and risky core edits. HeadRandom provides custom Perfex CRM module development, upgrade, and bug-fixing services for any third-party or custom module on your Perfex CRM installation, plus upgrading Perfex CRM from CodeIgniter 3 to CodeIgniter 4 via IgniteCore for Perfex CRM.

Build, Upgrade & Fix Any Perfex CRM Module

Develop new custom modules from scratch, patch bugs or hook conflicts on existing client modules, and update legacy code for clean PHP 8.2-8.4 compatibility with zero core file hacks. View Perfex CRM module development scope.

CodeIgniter 3 to CodeIgniter 4 via IgniteCore

Migrate your Perfex CRM runtime to CodeIgniter 4 (4.7.6) using IgniteCore for Perfex CRM (independent module by HeadRandom) with Dual-Mode CI3 fallback, 32% to 75% lower latency, 50% less RAM, and custom CI4 porting for third-party modules. See CI3 to CI4 upgrade options.

40+ Commercial Modules Published100% Zero Core File Edits0 High Security Audit GateTransparent Pricing from $39

Combine 2+ HeadRandom services (Custom Module, IgniteCore CI4 Upgrade, or Website Care) to save 30% automatically.