File tree Expand file tree Collapse file tree 2 files changed +18
-11
lines changed Expand file tree Collapse file tree 2 files changed +18
-11
lines changed Original file line number Diff line number Diff line change @@ -113,11 +113,21 @@ private function __construct()
113
113
);
114
114
}
115
115
116
+ /**
117
+ * Check if event loop is using UV extension.
118
+ *
119
+ * @return bool True if UV is available, false otherwise
120
+ */
116
121
public function isUsingUv (): bool
117
122
{
118
123
return UvDetector::isUvAvailable ();
119
124
}
120
125
126
+ /**
127
+ * Get the socket manager.
128
+ *
129
+ * @return SocketManager The socket manager instance
130
+ */
121
131
public function getSocketManager (): SocketManager
122
132
{
123
133
return $ this ->socketManager ;
@@ -264,15 +274,11 @@ public function run(): void
264
274
$ this ->optimizeLoop ();
265
275
}
266
276
267
- // Only sleep if NOT using UV
268
277
if (!$ isUsingUv && $ this ->sleepHandler ->shouldSleep ($ hasImmediateWork )) {
269
278
$ sleepTime = $ this ->sleepHandler ->calculateOptimalSleep ();
270
279
$ this ->sleepHandler ->sleep ($ sleepTime );
271
280
}
272
281
273
- // When using UV, let the UV loop control timing
274
- // Don't add any manual sleep - UV will handle it
275
-
276
282
if ($ this ->iterationCount >= self ::MAX_ITERATIONS ) {
277
283
$ this ->iterationCount = 0 ;
278
284
}
Original file line number Diff line number Diff line change 8
8
9
9
echo "Using UV: " . ($ loop ->isUsingUv () ? "YES " : "NO " ) . "\n" ;
10
10
11
- // Test timer precision
12
- $ start = microtime (true );
13
- for ( $ i = 0 ; $ i < 100 ; $ i ++ ) {
14
- $ loop -> addTimer ( 0.01 * $ i , function () use ( $ i ) {
15
- echo " Timer $ i fired \n" ;
11
+ for ( $ i = 1 ; $ i <= 10 ; $ i ++) {
12
+ $ startTime = microtime (true );
13
+ run ( function ( ) {
14
+ $ timers = array_fill ( 0 , 30000 , delay ( 1 ));
15
+ await ( all ( $ timers )) ;
16
16
});
17
+ $ endTime = microtime (true );
18
+ $ executionTime = $ endTime - $ startTime ;
19
+ echo "Execution time: " . $ executionTime . " seconds \n" ;
17
20
}
18
-
19
- $ loop ->run ();
You can’t perform that action at this time.
0 commit comments