« Back to Product

Documentation

IPS_GetScriptThread

 array IPS_GetScriptThread (int $ThreadID) 

Parameters

ThreadID

ID of the thread

Returns

The following information is available as key => value pairs:

Index Type Description
ThreadID integer ID of the thread
ExecuteCount integer Number of executions in this thread so far
ExecutionMin integer Shortest execution time in milliseconds
ExecutionAvg integer Average execution time in milliseconds
ExecutionMax integer Longest execution time in milliseconds
StartTime integer Unix timestamp of the start of the current execution, 0 if the thread is idle
Sender string Trigger of the current execution (value of $_IPS['SENDER'], e.g. "RunScript" or "TimerEvent"), empty if the thread is idle
SenderID integer ID of the triggering object (the event, the target instance or the script), 0 if the thread is idle (since version 9.0)
FilePath string What is currently executed: the script file relative to the program directory (e.g. "scripts/12345.ips.php"), the first 100 characters for script text, the executed function or timer for PHP modules, RunID and step for flow scripts; empty if the thread is idle
ScriptID integer ID of the executed script, 0 for script text or if the thread is idle
PeakMemoryUsage integer Highest memory usage of an execution in bytes since the last memory cleanup
RetainedMemoryUsage integer Memory in bytes that the thread keeps between executions, 0 after an unused thread has released its memory
MemoryCleanups integer Number of memory cleanups. If the memory usage of an execution exceeds the limit ThreadMemoryCleanup (default 10 MB), the thread releases its memory afterwards

Description

The function returns information about the thread with the ID ThreadID: the statistics of the previous executions, the memory usage and, if the thread is currently busy, the current execution. If the thread does not exist, the function fails with "ScriptThread #... does not exist".

PHP scripts are executed in a fixed pool of threads. The number of threads is set by the special switch ThreadCount (default 50, at least 25), and the threads have the IDs 1 to ThreadCount. Within a script, the system variable $_IPS['THREAD'] contains the ID of the own thread.

IPS_GetScriptThreadList returns the IDs of all threads, IPS_GetScriptThreads returns the information of several threads at once.

Example

// Information about the own thread
print_r(IPS_GetScriptThread($_IPS['THREAD']));

/* e.g. returns:
Array
(
    [ThreadID] => 3
    [ExecuteCount] => 152
    [ExecutionMin] => 0
    [ExecutionAvg] => 12
    [ExecutionMax] => 1530
    [StartTime] => 1758880000
    [Sender] => RunScript
    [SenderID] => 12345
    [FilePath] => scripts/12345.ips.php
    [ScriptID] => 12345
    [PeakMemoryUsage] => 2097152
    [RetainedMemoryUsage] => 2097152
    [MemoryCleanups] => 0
)
*/
Any questions?