php - Pthreads 启动不超过一个线程 php
问题描述
我想使用 pthreads,但运行以下脚本每秒只打印一个“1”,它应该每秒回显一个“123”,它只运行第一个线程。
<?php
require "/root/vendor/autoload.php";
set_time_limit( 0 );
function print_time( $id ) {
while( true ) {
print( $id );
sleep( 1 );
}
}
class Threaded_upload extends Thread {
public function __construct( $args ) {
$this->args = $args;
}
public function run() {
print_time( $this->args );
}
}
$thread_1 = new Threaded_upload( "1" );
$thread_1->start();
$thread_2 = new Threaded_upload( "2" );
$thread_2->start();
$thread_3 = new Threaded_upload( "3" );
$thread_3->start();
提前感谢您的帮助!
解决方案
推荐阅读
- javascript - 从javascript中的数组值的最后一个删除\ r
- laravel - 使用我的restful api更新,选择,发布时出现NotFoundHttpException
- perl - 将变量从 Perl 返回到 Batch
- c# - System.ServiceModel.CommunicationException:'服务端点未能侦听 URI'xxx',因为访问被拒绝
- macos - 如何获取文本字形的真实位置
- unity3d - Unity 单元测试失败,但 GitLab CI 管道作业通过(shell 执行器)
- php - Laravel 应用程序在升级到 php 8 后停止工作
- r - map over list, get item name and content
- iso8583 - Regarding ISO 8583 request response communication in javascript
- php - Passing variables from jQuery/AJAX to Wordpress php function does not work