Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,7 @@ devhub/pm-font/dist
test-db-snapshot.db
snapshot_*.db
storage/transitions
.envrc
.envrc
**/caddy
frankenphp
frankenphp-worker.php
2 changes: 2 additions & 0 deletions ProcessMaker/Http/Middleware/ServerTimingMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ public function handle(Request $request, Closure $next): Response
return $next($request);
}

ProcessMakerServiceProvider::beginRequestTiming();

// Start time for controller execution
$startController = microtime(true);

Expand Down
11 changes: 11 additions & 0 deletions ProcessMaker/Listeners/HandleRedirectListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,17 @@ protected function setRedirectTo(ProcessRequest $processRequest, string $method,
self::$redirectionParams = $params;
}

/**
* Reset the static state for Octane compatibility.
* This prevents data leaks between requests in long-running workers.
*/
public static function reset(): void
{
self::$processRequest = null;
self::$redirectionMethod = '';
self::$redirectionParams = [];
}

public static function sendRedirectToEvent()
{
$method = self::$redirectionMethod;
Expand Down
17 changes: 17 additions & 0 deletions ProcessMaker/Octane/ResetRequestState.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

declare(strict_types=1);

namespace ProcessMaker\Octane;

use ProcessMaker\Listeners\HandleRedirectListener;
use ProcessMaker\Providers\ProcessMakerServiceProvider;

final class ResetRequestState
{
public function handle(): void
{
ProcessMakerServiceProvider::beginRequestTiming();
HandleRedirectListener::reset();
}
}
45 changes: 38 additions & 7 deletions ProcessMaker/Providers/ProcessMakerServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,14 @@
use Illuminate\Support\Facades\Artisan;
use Illuminate\Support\Facades\Context;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Event;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Route;
use Illuminate\Support\Facades\URL;
use Laravel\Horizon\Horizon;
use Laravel\Horizon\SystemProcessCounter;
use Laravel\Horizon\WorkerCommandString;
use Laravel\Octane\Events\RequestTerminated;
use Laravel\Passport\Client as PassportClient;
use Lavary\Menu\Menu;
use OpenApi\Analysers\AttributeAnnotationFactory;
Expand All @@ -49,6 +51,7 @@
use ProcessMaker\Models;
use ProcessMaker\Multitenancy\Tenant;
use ProcessMaker\Observers;
use ProcessMaker\Octane\ResetRequestState;
use ProcessMaker\PolicyExtension;
use ProcessMaker\Providers\PermissionServiceProvider;
use ProcessMaker\Repositories\SettingsConfigRepository;
Expand Down Expand Up @@ -107,6 +110,9 @@ public function boot(): void

$this->checkConfigCache();

// Register Octane listeners if Octane is enabled
$this->registerOctaneListeners();

// Hook after service providers boot
self::$bootTime = (microtime(true) - self::$bootStart) * 1000; // Convert to milliseconds
}
Expand Down Expand Up @@ -260,7 +266,7 @@ protected static function registerEvents(): void
{
// Listen to the events for our core screen
// types and add our javascript
Facades\Event::listen(ScreenBuilderStarting::class, function ($event) {
Event::listen(ScreenBuilderStarting::class, function ($event) {
// Add any extensions to form builder
// and renderer from packages
$event->manager->addPackageScripts($event->type);
Expand All @@ -279,7 +285,7 @@ protected static function registerEvents(): void
});

// Log Notifications
Facades\Event::listen(NotificationSent::class, function ($event) {
Event::listen(NotificationSent::class, function ($event) {
$id = $event->notifiable->id;
$notifiable = get_class($event->notifiable);
$notification = get_class($event->notification);
Expand All @@ -288,24 +294,24 @@ protected static function registerEvents(): void
});

// Log Broadcasts (messages sent to laravel-echo-server and redis)
Facades\Event::listen(BroadcastNotificationCreated::class, function ($event) {
Event::listen(BroadcastNotificationCreated::class, function ($event) {
$channels = implode(', ', $event->broadcastOn());

Log::debug('Broadcasting Notification ' . $event->broadcastType() . 'on channel(s) ' . $channels);
});

// Fire job when task is assigned to a user
Facades\Event::listen(ActivityAssigned::class, function ($event) {
Event::listen(ActivityAssigned::class, function ($event) {
$task_id = $event->getProcessRequestToken()->id;
// Dispatch the SmartInbox job with the processRequestToken as parameter
SmartInbox::dispatch($task_id);
});

Facades\Event::listen(MadeTenantCurrentEvent::class, function ($event) {
Event::listen(MadeTenantCurrentEvent::class, function ($event) {
event(new TenantResolved($event->tenant));
});

Facades\Event::listen(TenantNotFoundForRequestEvent::class, function ($event) {
Event::listen(TenantNotFoundForRequestEvent::class, function ($event) {
if (config('app.multitenancy') === false || self::actuallyRunningInConsole()) {
// This is expected if multitenancy is disabled.
// We also need to check if we are running in a console command because
Expand All @@ -330,7 +336,7 @@ protected static function registerEvents(): void
}
});

Facades\Event::listen(function (CommandStarting $event) {
Event::listen(function (CommandStarting $event) {
if ($event->command === 'l5-swagger:generate') {
// Set the analyser to use the legacy DocBlockAnnotationFactory. This must
// be set here because this config value is not serializable and cannot be cached.
Expand Down Expand Up @@ -511,6 +517,14 @@ public static function getBootTime(): ?float
return self::$bootTime;
}

/**
* Reset per-request query timing metrics.
*/
public static function beginRequestTiming(): void
{
self::$queryTime = 0;
}

/**
* Get the query time for the request.
*
Expand Down Expand Up @@ -568,6 +582,23 @@ public static function getPackageBootTiming(): array
return self::$packageBootTiming;
}

/**
* Reset per-request static state between Octane requests.
*
* Octane workers stay alive across requests, so static properties must be
* cleared to avoid leaking data from one request into the next. Singletons
* holding mutable state are handled by the 'flush' list in config/octane.php,
* which Octane applies on its own.
*/
private function registerOctaneListeners(): void
{
if (!class_exists(RequestTerminated::class)) {
return;
}

Event::listen(RequestTerminated::class, ResetRequestState::class);
}

/**
* Find the tenant based on the environment variable
*/
Expand Down
2 changes: 1 addition & 1 deletion ProcessMaker/Repositories/SettingsConfigRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function get($key, $default = null)
if ($key === 'session.lifetime') {
$settingValue = $this->getFromSettings($key);

return $settingValue ?? $default;
return $settingValue ?: Arr::get($this->items, $key) ?: $default ?: 120;
}

if (Arr::has($this->items, $key)) {
Expand Down
7 changes: 4 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@
"guzzlehttp/psr7": "^2.12.3",
"igaster/laravel-theme": "^2.0",
"jenssegers/agent": "^2.6",
"laravel/framework": "^13.13",
"laravel/horizon": "^5.47",
"laravel/framework": "^13.0",
"laravel/horizon": "^5.45",
"laravel/octane": "^2.17",
"laravel/pail": "^1.2",
"laravel/passport": "^13.7",
"laravel/scout": "^11.1",
Expand Down Expand Up @@ -253,4 +254,4 @@
"ignore": []
}
}
}
}
Loading
Loading