本文整理汇总了PHP中xp_import函数的典型用法代码示例。如果您正苦于以下问题:PHP xp_import函数的具体用法?PHP xp_import怎么用?PHP xp_import使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了xp_import函数的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: dirname
<?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');
示例2: xp_import
<?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");
示例3: xp_import
<?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;
/**
示例4: round
$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);
示例5: xp_import
<?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;
});
示例6: xp_import
<?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 : ");
});
$socket->on_read(null);
$socket->on_read(function (network\SIG_Read $sig_read) use($socket) {
$clients = $socket->get_connections();
$client = $clients[intval($sig_read->socket->get_resource())];
// Strip any newlines from linux
$sig_read->socket->_read_buffer();
$content = implode("", explode("\r\n", $sig_read->socket->read()));
// windows
$content = implode("", explode("\n\r", $content));
// On first connection read in the username