LuaSandbox::pauseUsageTimer

(PECL luasandbox >= 1.4.0)

LuaSandbox::pauseUsageTimerPause the CPU usage timer

Beschreibung

public LuaSandbox::pauseUsageTimer(): bool

Pauses the CPU usage timer.

This only has effect when called from within a callback from Lua. When execution returns to Lua, the timer will be automatically unpaused. If a new call into Lua is made, the timer will be unpaused for the duration of that call.

If a PHP callback calls into Lua again with timer not paused, and then that Lua function calls into PHP again, the second PHP call will not be able to pause the timer. The logic is that even though the second PHP call would avoid counting the CPU usage against the limit, the first call still counts it.

Parameter-Liste

Diese Funktion besitzt keine Parameter.

Rückgabewerte

Returns a bool indicating whether the timer is now paused.

Beispiele

Beispiel #1 Manipulating the usage timer

<?php

// create a new LuaSandbox and set a CPU limit
$sandbox = new LuaSandbox();
$sandbox->setCPULimit);

function 
doWait$t ) {
    
$end microtimetrue ) + $t;
    while ( 
microtimetrue ) < $end ) {
        
// waste CPU cycles
    
}
}

// Register a PHP callback
$sandbox->registerLibrary'php', [
    
'test' => function () use ( $sandbox ) {
        
$sandbox->pauseUsageTimer();
        
doWait);

        
$sandbox->unpauseUsageTimer();
        
doWait0.1 );
    },
    
'test2' => function () use ( $sandbox ) {
        
$sandbox->pauseUsageTimer();
        
$sandbox->unpauseUsageTimer();
        
doWait1.1 );
    }
] );

echo 
"This should not time out...\n";
$sandbox->loadString'php.test()' )->call();

echo 
"This should time out.\n";
try {
    
$sandbox->loadString'php.test2()' )->call();
    echo 
"It did not?\n";
} catch ( 
LuaSandboxTimeoutError $ex ) {
    echo 
"It did! " $ex->getMessage() . "\n";
}

?>

Das oben gezeigte Beispiel erzeugt folgende Ausgabe:

This should not time out...
This should time out.
It did! The maximum execution time for this script was exceeded

Siehe auch

Hier Kannst Du einen Kommentar verfassen


Bitte gib mindestens 10 Zeichen ein.
Wird geladen... Bitte warte.
* Pflichtangabe
Es sind noch keine Kommentare vorhanden.

Was genau bedeutet "Vibe Coding"? Ein tiefgehender Blick für Entwickler

In der Welt der Softwareentwicklung gibt es unzählige Wege, wie man an ein Projekt herangeht. Manche schwören auf strikte Planung, andere auf bewährte Algorithmen und wieder andere lassen sich von etwas ganz anderem leiten: ihrem Gefühl. ...

admin

Autor : admin
Kategorie: Software & Web-Development

PHP cURL-Tutorial: Verwendung von cURL zum Durchführen von HTTP-Anfragen

cURL ist eine leistungsstarke PHP-Erweiterung, die es Ihnen ermöglicht, mit verschiedenen Servern über verschiedene Protokolle wie HTTP, HTTPS, FTP und mehr zu kommunizieren. ...

TheMax

Autor : TheMax
Kategorie: PHP-Tutorials

Midjourney Tutorial - Anleitung für Anfänger

Über Midjourney, dem Tool zur Erstellung digitaler Bilder mithilfe von künstlicher Intelligenz, gibt es ein informatives Video mit dem Titel "Midjourney Tutorial auf Deutsch - Anleitung für Anfänger" ...

Mike94

Autor : Mike94
Kategorie: KI Tutorials

Tutorial veröffentlichen

Tutorial veröffentlichen

Teile Dein Wissen mit anderen Entwicklern weltweit

Du bist Profi in deinem Bereich und möchtest dein Wissen teilen, dann melde dich jetzt an und teile es mit unserer PHP-Community

mehr erfahren

Tutorial veröffentlichen

SEO: Worauf sollte man sich konzentrieren?

Hier sind einige wichtige Aspekte, auf die man sich bei der Suchmaschinenoptimierung (SEO) konzentrieren sollte, sowie eine Analyse der Stärken d ...

Geschrieben von ruletaa am 11.04.2025 03:55:50
Forum: SEO - Suchmaschinen Tricks und Tipps
Google findet die Seite einfach nicht...

Sie können die folgenden Websites aufrufen, um Ihre SEO-bezogene Konfiguration zu verfeinern: Ruletaa (https://ruletaa.net) HixAI (https://hix.ai)

Geschrieben von ruletaa am 11.04.2025 03:48:33
Forum: SEO - Suchmaschinen Tricks und Tipps
Keine Moderation?

Ja, das ist echt schade. Shopware Freelancer (https://stefanpilz.ltd/)

Geschrieben von Stefan_Pilz am 10.04.2025 15:42:50
Forum: Fragen/Vorschläge zum Forum
Seltsames Verhalten von execute() oder Fehler meinerseits

The level of brilliance that you have displayed here is nothing short of astounding. Your performance has not even come close to meeting my expect ...

Geschrieben von sloperun3az am 09.04.2025 12:22:39
Forum: SQL / Datenbanken