Beispiel #1
0
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
class AsyncOperation extends Thread
{
    public function __construct($arg)
    {
        $this->arg = $arg;
    }
    public function run()
    {
        if ($this->arg) {
            printf("Hello %s\n", $this->arg);
        }
    }
}
$thread = new AsyncOperation("World");
if ($thread->start()) {
    $thread->join();
}
?>

Beispiel #2
0
<?php

class AsyncOperation extends Thread
{
    public function __construct($arg)
    {
        $this->arg = $arg;
    }
    public function run()
    {
        if ($this->arg) {
            for ($i = 0; $i < 5; $i++) {
                echo "-> " . $this->arg . "\n";
                sleep(1);
            }
        }
    }
}
flush();
$thread = new AsyncOperation("Thread 1");
$thread2 = new AsyncOperation("Thread 2");
$thread->start();
$thread2->start();
$thread->join();
$thread2->join();