2014-01-10 21 views
0
class testing extends Thread { 
    public $client; 
    public function __construct($persons) { // set passed arguments 
     $this->persons = $persons; 
    } 
    public function run() { // run thread 
     $this->client = new Services_Twilio('my_id', 'my_token'); 
     printf('%s: %s' . "<br>", date("g:i:sa"), $this->client->account->sms_messages->create($this->persons[0], $this->persons[1], $this->persons[2])->sid); 
    } 
} 

$testing= new multipleSMS(['+XXXXXXXXXXXX', 'xxx-xxx-xxxx', 'A sample message']); 
$testing->start(); 

这给了我错误:Warning: in_array() expects parameter 2 to be array, null given in twilio-php-master\Services\Twilio.php on line 59。因此,在$this->client我给它一个数组。当我使用新services_twilio类的线程之外它工作得很好。pthreads:调用线程内的阵列不工作

我在做什么错。

+0

我会回答... –

回答

1

你不打算分享这个 - $>客户端,所以不要将其设置为线程中的一员,保持它在方法的范围,避免用这种方式锁定和系列化。

只有分享被设计为共享(从并行线程递减),并要求分享(你打算从另一个上下文访问)。