<?php /** * Copyright 2010-12 Nickolas Whiting. All rights reserved. * Use of this source code is governed by the Apache 2 license * that can be found in the LICENSE file. */ require_once dirname(realpath(__FILE__)) . '/../__init__.php'; xp_import('unittest'); xp_import('time'); unittest\test(function ($test) { $processor = new \XPSPL\Processor(); $start = time(); $processor->signal(new \time\SIG_Awake(1, TIME_SECONDS), new \XPSPL\Process(function () use($start, $test) { $test->equal(1, time() - $start); }, 1)); $processor->wait_loop(); }, 'Time Module');
<?php /** * Copyright 2010-12 Nickolas Whiting. All rights reserved. * Use of this source code is governed by the Apache 2 license * that can be found in the LICENSE file. */ require_once '__init__.php'; xp_import('unittest'); unittest\test(function ($test) { $db = new \XPSPL\database\Processes(); $p1 = new \XPSPL\Process(null); $p2 = xp_high_priority(new \XPSPL\Process(null)); $db->install($p1); $db->install($p2); $db->delete($p1); $test->equal($db->count(), 1); $test->equal($db->current()->get_priority(), 0); }, "process delete");
<?php namespace network; /** * Copyright 2010-12 Nickolas Whiting. All rights reserved. * Use of this source code is governed by the Apache 2 license * that can be found in the LICENSE file. */ xp_import('logger'); use XPSPL\idle\Process, XPSPL\idle\Time; /** * Socket * * Event driven I/O. */ class Socket extends \XPSPL\SIG_Routine { /** * Socket connection object * * @var object */ protected $_connection = null; /** * Socket Address * * @var string */ protected $_address = null; /**
$lines++; } if ($_v >= 1) { $total++; } } $avg[$file] = round($total / $lines * 100, 2); } else { $avg[$file] = 0; } }, $_file); } $total = 0.0; foreach ($avg as $_c) { $total += $_c; } \unittest\Output::send('--------------------', \unittest\Output::DEBUG, true); \unittest\Output::send(sprintf('Total Test Coverage : %s%%', round($total / (count($avg) * 100) * 100, 2)), \unittest\Output::DEBUG, true); \unittest\Output::send('--------------------', \unittest\Output::DEBUG, true); foreach ($avg as $_k => $_c) { \unittest\Output::send(sprintf('File : %s', $_k), \unittest\Output::DEBUG, true); \unittest\Output::send(sprintf('Coverage : %s%%', $_c), \unittest\Output::DEBUG, true); \unittest\Output::send('--------------------', \unittest\Output::DEBUG, true); } }); } xp_import("unittest"); // load the standard unittest output unittest\generate_output(); // make sure we save the event history xp_set_signal_history(true);
<?php xp_import('time'); xp_import('ftp'); // Must provide username/password $connection = ['hostname' => 'ftps://app.brickftp.com', 'username' => '-', 'password' => '-', 'secure' => false]; $files = [dirname(realpath(__FILE__)) . '/file_1.txt', dirname(realpath(__FILE__)) . '/file_2.txt', dirname(realpath(__FILE__)) . '/file_3.txt', dirname(realpath(__FILE__)) . '/file_4.txt']; $uploader = ftp\upload($files, $connection, function ($signal) { echo "Upload Started" . PHP_EOL; }); ftp\complete($uploader, function ($signal) { echo $signal->get_file()->get_name() . ' uploaded succesfully' . PHP_EOL; }); ftp\failure($uploader, function ($signal) { echo $signal->get_file()->get_name() . ' failed to upload' . PHP_EOL; });
<?php /** * Copyright 2010-12 Nickolas Whiting. All rights reserved. * Use of this source code is governed by the Apache 2 license * that can be found in the LICENSE file. */ /** * Chat Server * * This example demonstrates how to build a simple TCP chat server which can * be connected using telnet. */ xp_import('network'); $socket = network\connect('0.0.0.0', ['port' => '8000'], function () { echo "Server Running on " . $this->socket->get_address() . PHP_EOL; }); $socket->on_connect(function (network\SIG_Connect $sig_connect) use($socket) { $sig_connect->socket->write("Welcome to the prggmr chat server" . PHP_EOL); $sig_connect->socket->write("Enter your username : "******"", explode("\r\n", $sig_read->socket->read())); // windows $content = implode("", explode("\n\r", $content)); // On first connection read in the username