PHP Classes

File: test/classes/EchoThread.php

Recommend this page to a friend!
  Classes of AlexanderC   Threadator   test/classes/EchoThread.php   Download  
File: test/classes/EchoThread.php
Role: Auxiliary script
Content type: text/plain
Description: Auxiliary script
Class: Threadator
Create threads and send messages between them
Author: By
Last change: Update of test/classes/EchoThread.php
Date: 5 months ago
Size: 1,122 bytes
 

Contents

Class file image Download
<?php
/**
 * @author AlexanderC <self@alexanderc.me>
 * @date 4/9/14
 * @time 9:58 AM
 */

/** Class definition */
class EchoThread extends \Threadator\Thread
{
   
/**
     * @var
     */
   
protected $stringToEcho;

   
/**
     * @param mixed $stringToEcho
     */
   
public function setStringToEcho($stringToEcho)
    {
       
$this->stringToEcho = (string) $stringToEcho;
    }

   
/**
     * @return mixed
     */
   
public function getStringToEcho()
    {
        return
$this->stringToEcho;
    }

   
/**
     * @return void
     */
   
protected function _run()
    {
       
$mutex = $this->createMutex('echo', \Threadator\Mutex::T_FUNCTION);

       
// send a message
       
$this->sendMessage("#{$this->getPid()} ok");

       
sleep(mt_rand(1, 3));

       
$mutex->waitAcquire();
        echo
$this->stringToEcho, "\n";
       
$mutex->release();
    }

   
/**
     * @return void
     */
   
protected function unload()
    {
       
// TODO: Implement unload() method.
   
}

   
/**
     * @return void
     */
   
protected function init()
    {
       
// TODO: Implement init() method.
   
}
}