Returns the request connection status bitmask: normal, aborted or timed out.
The examples focus on the operation itself, including the important distinction: connection_aborted tests whether an abort bit was detected.
What It Does
Use the examples below to observe the behavior on a small dataset before extending it to application code.
Syntax and Return Value
connection_status(): int
The displayed signature describes the API or identifies any correction or optional dependency. When a parameter is optional, supply it only when the task requires it.
Declared return type: int. Read the behavior notes for important cases such as empty collections and destructive iteration.
Example 1: Basic Use
The return is a bitmask. Compare using bitwise AND rather than matching a single number.
<?php
$status = connection_status();
echo ($status & CONNECTION_ABORTED) ? "aborted" : "not aborted";
echo ($status & CONNECTION_TIMEOUT) ? ", timed out" : ", not timed out";
Output from a successful local PHP 8.4 run:
not aborted, not timed out
Example 2: Checking Behavior
The return is a bitmask. Compare using bitwise AND rather than matching a single number. The overall status and the separate bit flags can be inspected independently.
<?php
$status = connection_status();
echo ($status & CONNECTION_ABORTED) ? "aborted" : "not aborted";
echo ($status & CONNECTION_TIMEOUT) ? ", timed out" : ", not timed out";
echo " raw-status=" . $status;
Output from a successful local PHP 8.4 run:
not aborted, not timed out raw-status=0
Example 3: Practical Example
The return is a bitmask. Compare using bitwise AND rather than matching a single number. The overall status and the separate bit flags can be inspected independently.
<?php
$status = connection_status();
echo ($status & CONNECTION_ABORTED) ? "aborted" : "not aborted";
echo ($status & CONNECTION_TIMEOUT) ? ", timed out" : ", not timed out";
echo " normal=" . ($status === CONNECTION_NORMAL ? "yes" : "no");
Output from a successful local PHP 8.4 run:
not aborted, not timed out normal=yes
Important Behavior and Edge Cases
Do not use == against a single flag if more than one status bit may be set.
Comparison with Related Approaches
| Approach | Difference |
|---|---|
| connection_status | Returns the request connection status bitmask: normal, aborted or timed out. |
| Related API or alternative | connection_aborted tests whether an abort bit was detected. |
Common Beginner Mistakes
| Mistake | Correct approach |
|---|---|
| Ignoring the operation-specific limits | Do not use == against a single flag if more than one status bit may be set. |
| Confusing it with a related API | connection_aborted tests whether an abort bit was detected. |
Key Takeaways
- Returns the request connection status bitmask: normal, aborted or timed out.
- Do not use == against a single flag if more than one status bit may be set.
- connection_aborted tests whether an abort bit was detected.
Use connection_status when its documented behavior matches the problem. Test the relevant edge cases in your own runtime before deploying it.