com phpruntests: phpruntests - added taskScheduler-prototype: code-samples/taskScheduler/classes/task.php
code-samples/taskScheduler/classes/taskInterface.php code-samples/taskScheduler/classes/taskScheduler.php code-samples/taskScheduler/example1/main.php
code-samples/taskScheduler/example1/taskCalculate.php code-samples/taskScheduler/example2/main.php code-samples/taskScheduler/example2/taskSleep.php
code-samples/taskScheduler/example3/files/sr
| From: | David Soria Parra | Date: | Sat, 13 Jun 2009 03:13:31 +0000 |
| Subject: | com phpruntests: phpruntests - added taskScheduler-prototype: code-samples/taskScheduler/classes/task.php code-samples/taskScheduler/classes/taskInterface.php code-samples/taskScheduler/classes/taskScheduler.php code-samples/taskScheduler/example1/main.php code-samples/taskScheduler/example1/taskCalculate.php code-samples/taskScheduler/example2/main.php code-samples/taskScheduler/example2/taskSleep.php code-samples/taskScheduler/example3/files/sr |
||
| Groups: | php.qa | ||
| Request: | Send a blank email to php-qa+get-66415@lists.php.net to get a copy of this message | ||
Commit: dcad19f319fd7ee046fb52af8d7b8a14604d2770
Author: Georg Gradwohl <g2@php.net> Sat, 13 Jun 2009 03:13:31 +0000
Parents: accf23d7a3e36c8e431f346f0d634a7ee1a54022
Branches: master
Link: http://git.php.net/?p=phpruntests.git;a=commitdiff;h=dcad19f319fd7ee046fb52af8d7b8a14604d2770
Log:
phpruntests - added taskScheduler-prototype
Changed paths:
A code-samples/taskScheduler/classes/task.php
A code-samples/taskScheduler/classes/taskInterface.php
A code-samples/taskScheduler/classes/taskScheduler.php
A code-samples/taskScheduler/example1/main.php
A code-samples/taskScheduler/example1/taskCalculate.php
A code-samples/taskScheduler/example2/main.php
A code-samples/taskScheduler/example2/taskSleep.php
A code-samples/taskScheduler/example3/files/src/adv/008.phpt
A code-samples/taskScheduler/example3/files/src/adv/009.phpt
A code-samples/taskScheduler/example3/files/src/adv/010.phpt
A code-samples/taskScheduler/example3/files/src/adv/011.phpt
A code-samples/taskScheduler/example3/files/src/adv/012.phpt
A code-samples/taskScheduler/example3/files/src/adv/013.phpt
A code-samples/taskScheduler/example3/files/src/adv/014.phpt
A code-samples/taskScheduler/example3/files/src/adv/015.phpt
A code-samples/taskScheduler/example3/files/src/adv/016.phpt
A code-samples/taskScheduler/example3/files/src/adv/017.phpt
A code-samples/taskScheduler/example3/files/src/adv/018.phpt
A code-samples/taskScheduler/example3/files/src/adv/019.phpt
A code-samples/taskScheduler/example3/files/src/adv/020.phpt
A code-samples/taskScheduler/example3/files/src/adv/022.phpt
A code-samples/taskScheduler/example3/files/src/adv/023.phpt
A code-samples/taskScheduler/example3/files/src/adv/024.phpt
A code-samples/taskScheduler/example3/files/src/adv/025.phpt
A code-samples/taskScheduler/example3/files/src/adv/026.phpt
A code-samples/taskScheduler/example3/files/src/adv/027.phpt
A code-samples/taskScheduler/example3/files/src/basic/001.phpt
A code-samples/taskScheduler/example3/files/src/basic/002.phpt
A code-samples/taskScheduler/example3/files/src/basic/003.phpt
A code-samples/taskScheduler/example3/files/src/basic/004.phpt
A code-samples/taskScheduler/example3/files/src/basic/005.phpt
A code-samples/taskScheduler/example3/files/src/basic/006.phpt
A code-samples/taskScheduler/example3/files/src/basic/007.phpt
A code-samples/taskScheduler/example3/files/src/func/001.phpt
A code-samples/taskScheduler/example3/files/src/func/002.phpt
A code-samples/taskScheduler/example3/files/src/func/003.phpt
A code-samples/taskScheduler/example3/files/src/func/004.phpt
A code-samples/taskScheduler/example3/files/src/func/005.phpt
A code-samples/taskScheduler/example3/files/src/func/005a.phpt
A code-samples/taskScheduler/example3/files/src/func/006.phpt
A code-samples/taskScheduler/example3/files/src/func/007.phpt
A code-samples/taskScheduler/example3/files/src/func/008.phpt
A code-samples/taskScheduler/example3/files/src/func/009.phpt
A code-samples/taskScheduler/example3/files/src/func/010.phpt
A code-samples/taskScheduler/example3/imgConverter/fileCreator.php
A code-samples/taskScheduler/example3/imgConverter/fileReader.php
A code-samples/taskScheduler/example3/imgConverter/imageCreator.php
A code-samples/taskScheduler/example3/imgConverter/imageReader.php
A code-samples/taskScheduler/example3/main.php
A code-samples/taskScheduler/example3/taskConvert.php
A code-samples/taskScheduler/run.php
diff --git a/code-samples/taskScheduler/classes/task.php b/code-samples/taskScheduler/classes/task.php new file mode 100644 index 0000000..7712dd8 --- /dev/null +++ b/code-samples/taskScheduler/classes/task.php @@ -0,0 +1,48 @@ +<?php + +abstract class task +{ + const NOEX = 0; + const PASS = 1; + const FAIL = -1; + + private $state = self::NOEX; + private $index = NULL; + private $message = NULL; + + + public function setState($state) + { + $this->state = $state; + } + + public function getState() + { + return $this->state; + } + + + public function setMessage($msg) + { + $this->message = $msg; + } + + public function getMessage() + { + return $this->message; + } + + + public function setIndex($index) + { + $this->index = $index; + } + + public function getIndex() + { + return $this->index; + } + +} + +?> \ No newline at end of file diff --git a/code-samples/taskScheduler/classes/taskInterface.php b/code-samples/taskScheduler/classes/taskInterface.php new file mode 100644 index 0000000..a682db6 --- /dev/null +++ b/code-samples/taskScheduler/classes/taskInterface.php @@ -0,0 +1,8 @@ +<?php + +interface taskInterface +{ + public function run(); +} + +?> \ No newline at end of file diff --git a/code-samples/taskScheduler/classes/taskScheduler.php b/code-samples/taskScheduler/classes/taskScheduler.php new file mode 100644 index 0000000..d379ea6 --- /dev/null +++ b/code-samples/taskScheduler/classes/taskScheduler.php @@ -0,0 +1,475 @@ +<?php + +declare(ticks=true); + + +class taskScheduler +{ + const MSG_QUEUE_KEY = 1234; // id of the message-queue + const MSG_QUEUE_SIZE = 1024; // max-size of a single message + const KILL_CHILD = 'killBill'; // kill-signal to terminate a child + + private $taskList = array(); + private $processCount = NULL; + private $inputQueue = NULL; + private $pidStore = array(); + private $time = 0; + private $countPass = 0; + private $countFail = 0; + private $groupTasks = false; + + + /** + * the constructor + * + * @param array $taskList (optional) + * @param int $processCount (optional) + */ + public function __construct(array $taskList=NULL, $processCount=NULL) + { + if (is_array($taskList)) { + $this->setTaskList($taskList); + } + + $this->setProcessCount($processCount); + } + + + /** + * sets the task-list which has to be an array of task-objects. + * it's also possible to use a multidimensional array. in this case the + * tasks are distributed to the child-processes exactly in the way as they + * are grouped in the list. the first-level index strictly has to be + * numeric and continuous starting with zero. + * + * @param array $taskList + */ + public function setTaskList(array $taskList) + { + if (is_array($taskList[0])) { + $this->groupTasks = true; + $this->processCount = sizeof($taskList); + } + + $this->taskList = $taskList; + } + + + /** + * @return array $taskList + */ + public function getTaskList() + { + return $this->taskList; + } + + + /** + * sets the number of child-processes. + * in the case of using a multidimensional task-list this parameter is + * ignored and set to the number of task-groups. + * + * @param int $count + */ + public function setProcessCount($processCount) + { + if ($this->groupTasks !== true && is_numeric($processCount) && $processCount >= 0) { + $this->processCount = $processCount; + } + } + + + /** + * removes the used message-queues. + */ + private static function cleanUp() + { + @msg_remove_queue(msg_get_queue(self::MSG_QUEUE_KEY)); + @msg_remove_queue(msg_get_queue(self::MSG_QUEUE_KEY+1)); + logg("CLEAN UP"); + } + + + /** + * the signal-handler is called by the interrupt- or quit-signal and calls + * the cleanUp-method. + * + * @param int $signal + */ + public static function signalHandler($signal) + { + logg("SIGNAL: $signal"); + + switch($signal) { + + case SIGINT: + case SIGQUIT: + self::cleanUp(); + die("\n"); + break; + + default: + break; + } + } + + /** + * switch to run the classic- or the fork-mode + */ + public function run() + { + if ($this->processCount > 0) { + $this->runFork(); + } + else $this->runClassic(); + } + + + /** + * executes the tasks in a simple loop + * + * @return void + */ + private function runClassic() + { + $s = microtime(true); + + for ($i=0; $i<sizeof($this->taskList); $i++) { + + $task = $this->taskList[$i]; + + if ($task->run() === true) { + $task->setState(task::PASS); + $this->countPass++; + } else { + $task->setState(task::FAIL); + $this->countFail++; + } + + print "."; + flush(); + + $this->taskList[$i] = $task; + } + + $error = microtime(true); + + $this->time = round($error-$s,5); + + return; + } + + + /** + * starts the sender, the receiver and forks the defined + * number of child-processes. + * + * @return void + */ + private function runFork() + { + $startTime = microtime(true); + + // register signal-handler + pcntl_signal(SIGINT, "taskScheduler::signalHandler"); + pcntl_signal(SIGQUIT, "taskScheduler::signalHandler"); + + // trim the processCount if nesecarry + if (is_null($this->processCount) || $this->processCount > sizeof($this->taskList)) { + $this->processCount = sizeof($this->taskList); + } + + // fork the child-processes + for ($i=0; $i<=$this->processCount; $i++) { + + $this->pidStore[$i] = pcntl_fork(); + + switch ($this->pidStore[$i]) { + + case -1: // failure + die("could not fork"); + break; + + case 0: // child + if ($i==0) { + $this->sender(); + } else { + $cid = ($this->groupTasks == true) ? $i : NULL; + $this->child($cid); + } + break; + + default: // parent + break; + } + } + + // start the receiver + $this->receiver(); + + // wait until all child-processes are terminated + for ($i=0; $i<=$this->processCount; $i++) { + + pcntl_waitpid($this->pidStore[$i], $status); + logg("child $i terminated - status $status"); + } + + $endTime = microtime(true); + $this->time = round($endTime-$startTime,5); + + // remove the msg-queue + self::cleanUp(); + + logg("EXIT MAIN"); + return; + } + + + /** + * the receiver is listening to the result-queue and stores the incomming + * tasks back to the task-list. + * when finished it sends the kill-signal to all children and terminates + * itself. + * + * @return void + */ + private function receiver() + { + logg("RECEIVER START - ".sizeof($this->taskList)." tasks"); + + $resultQueue = msg_get_queue(self::MSG_QUEUE_KEY+1); + + $task = ''; + $type = 1; + + if ($this->groupTasks == true) { + $limit = 0; + foreach ($this->taskList as $list) { + $limit += sizeof($list); + } + } else { + $limit = sizeof($this->taskList); + } + + for ($i=0; $i<$limit; $i++) { + + if (msg_receive($resultQueue, 0, $type, self::MSG_QUEUE_SIZE, $task, true, NULL, $error)) { + + // check state + if ($task->getState() == task::PASS) { + $this->countPass++; + } else { + $this->countFail++; + } + + // store result + $index = $task->getIndex(); + + if ($this->groupTasks == true) { + $this->taskList[$type-2][$index] = $task; + logg("RECEIVER store task ".($type-1)."-$index"); + + } else { + $this->taskList[$index] = $task; + logg("RECEIVER store task $index"); + } + } + else logg("RECEIVER ERROR $error"); + } + + $inputQueue = msg_get_queue(self::MSG_QUEUE_KEY); + + for ($i=1; $i<=$this->processCount; $i++) { + + if (msg_send($inputQueue, $i, self::KILL_CHILD, true, true, $error)) { + + logg("RECEIVER send KILL_CHILD"); + } + else logg("RECEIVER ERROR $error"); + } + + logg("RECEIVER EXIT"); + return; + } + + + /** + * the sender is passes through the task-list and distributes the single + * tasks to the child-processes using the input-queue. + * when finished it terminates itself. + * + * @return void + */ + private function sender() + { + logg("SENDER START - ".sizeof($this->taskList)." tasks"); + + $this->inputQueue = msg_get_queue(self::MSG_QUEUE_KEY); + + for ($i=0; $i<sizeof($this->taskList); $i++) { + + if ($this->groupTasks == true) { + + for ($j=0; $j<sizeof($this->taskList[$i]); $j++) { + + $this->sendTask($this->taskList[$i][$j], $j, $i+1); + } + + } else { + + $this->sendTask($this->taskList[$i], $i); + } + } + + logg("SENDER EXIT"); + exit(0); + } + + + /** + * helper-class of sender. + * sends a task to a child-process using the input-queue. + * + * @param task $task the task to send + * @param int $index the task's index in the taskList + * @param int $type the message-type (default=1) + * @return void + */ + private function sendTask(task $task, $index, $type=1) + { + $task->setIndex($index); + + if (msg_send($this->inputQueue, $type, $task, true, true, $error)) { + + logg("SENDER send task $type - $index"); + } + else logg("SENDER ERROR $error"); + + return; + } + + + /** + * the child is listening to the input-queue and executes the incomming + * tasks. afterwards it setts the task-state and sends it back to the + * receiver by the result-queue. + * after receiving the kill-signal from the receiver it terminates itself. + * + * @param int $cid the child-id (default=NULL) + * @return void + */ + private function child($cid=NULL) + { + if (is_null($cid)) { + $cid = 0; + } + + logg("child $cid START"); + + $inputQueue = msg_get_queue(self::MSG_QUEUE_KEY); + $resultQueue = msg_get_queue(self::MSG_QUEUE_KEY+1); + + $type = 1; + + while (true) { + + if (msg_receive($inputQueue, $cid, $type, self::MSG_QUEUE_SIZE, $task, true, NULL, $error)) { + + if ($task == self::KILL_CHILD) + break; + + $index = $task->getIndex(); + + logg("child $cid - run task $index"); + + if ($task->run() === true) { + $task->setState(task::PASS); + } else { + $task->setState(task::FAIL); + } + + print "."; + flush(); + + if (msg_send($resultQueue, $cid+1, $task, true, true, $error)) { + + logg("child $cid - send task $index"); + } + else logg("child $cid ERROR $error"); + + } + else logg("child $cid ERROR $error"); + } + + logg("child $cid EXIT"); + exit(0); + } + + + /** + * prints the statistic + * + * @return void + */ + public function printStatistic() + { + print "\n----------------------------------------\n"; + + if ($this->groupTasks == true) { + + $count = 0; + foreach ($this->taskList as $list) { + $count += sizeof($list); + } + + print "Groups:\t\t".sizeof($this->taskList)."\n"; + print "Tasks:\t\t".$count."\n"; + + } else { + $count = sizeof($this->taskList); + print "Tasks:\t\t".$count."\n"; + } + + print "PASSED:\t\t".$this->countPass." (".round($this->countPass/$count*100,2)."%)\n"; + print "FAILED:\t\t".$this->countFail." (".round($this->countFail/$count*100,2)."%)\n"; + print "Processes:\t".$this->processCount."\n"; + print "Seconds:\t".$this->time."\n"; + + if ($this->processCount > 0) { + print "AVG sec/task:\t".round($this->time/$this->processCount,5)."\n"; + } + + print "----------------------------------------\n"; + flush(); + } + + + /** + * prints a overview of the faild tasks + * + * @return void + */ + public function printFailedTasks() + { + if ($this->countFail > 0) { + + print "FAILED TASKS"; + print "\n----------------------------------------\n"; + + for ($i=0; $i<sizeof($this->taskList); $i++) { + + $task = $this->taskList[$i]; + + if ($task->getState() == task::FAIL) { + print "Task $i: ".$task->getMessage()."\n"; + } + } + + print "----------------------------------------\n"; + flush(); + } + } + +} + +?> \ No newline at end of file diff --git a/code-samples/taskScheduler/example1/main.php b/code-samples/taskScheduler/example1/main.php new file mode 100644 index 0000000..2f3ae1d --- /dev/null +++ b/code-samples/taskScheduler/example1/main.php @@ -0,0 +1,25 @@ +<?php + +include 'taskCalculate.php'; + + +function createTaskList() +{ + $list = array(); + + for ($i=0; $i<rand(128,256); $i++) { + + $num = array(); + + for ($j=0; $j<rand(32,64); $j++) { + + $num[$j] = rand(0,9); + } + + $list[$i] = new taskCalculate($num); + } + + return $list; +} + +?> \ No newline at end of file diff --git a/code-samples/taskScheduler/example1/taskCalculate.php b/code-samples/taskScheduler/example1/taskCalculate.php new file mode 100644 index 0000000..114071d --- /dev/null +++ b/code-samples/taskScheduler/example1/taskCalculate.php @@ -0,0 +1,44 @@ +<?php + +class taskCalculate extends task implements taskInterface +{ + private $numbers = array(); + private $result = 0; + + + public function __construct(array $numbers) + { + $this->numbers = $numbers; + } + + + public function run() + { + $r = 0; + + foreach($this->numbers as $num) { + + $num = (int)$num; + $r += $num; + } + + if ($r%26 == 0) { + + $this->setMessage("just an example"); + return false; + } + + $this->result = $r; + return true; + } + + + public function getResult() + { + return $this->result; + } + +} + + +?> \ No newline at end of file diff --git a/code-samples/taskScheduler/example2/main.php b/code-samples/taskScheduler/example2/main.php new file mode 100644 index 0000000..f7599ae --- /dev/null +++ b/code-samples/taskScheduler/example2/main.php @@ -0,0 +1,18 @@ +<?php + +include 'taskSleep.php'; + + +function createTaskList() +{ + $list = array(); + + for ($i=0; $i<10; $i++) { + + $list[$i] = new taskSleep($i%3); + } + + return $list; +} + +?> \ No newline at end of file diff --git a/code-samples/taskScheduler/example2/taskSleep.php b/code-samples/taskScheduler/example2/taskSleep.php new file mode 100644 index 0000000..66e712f --- /dev/null +++ b/code-samples/taskScheduler/example2/taskSleep.php @@ -0,0 +1,22 @@ +<?php + +class taskSleep extends task implements taskInterface +{ + private $sleep = 0; + + + public function __construct($sleep) + { + $this->sleep = $sleep; + } + + + public function run() + { + sleep($this->sleep); + return true; + } +} + + +?> \ No newline at end of file diff --git a/code-samples/taskScheduler/example3/files/src/adv/008.phpt b/code-samples/taskScheduler/example3/files/src/adv/008.phpt new file mode 100644 index 0000000..511aef0 --- /dev/null +++ b/code-samples/taskScheduler/example3/files/src/adv/008.phpt @@ -0,0 +1,6 @@ +--TEST-- +Divide 3 variables and print result +--FILE-- +<?php $a=27; $b=3; $c=3; $d=$a/$b/$c; echo $d?> +--EXPECT-- +3 diff --git a/code-samples/taskScheduler/example3/files/src/adv/009.phpt b/code-samples/taskScheduler/example3/files/src/adv/009.phpt new file mode 100644 index 0000000..fefe529 --- /dev/null +++ b/code-samples/taskScheduler/example3/files/src/adv/009.phpt @@ -0,0 +1,6 @@ +--TEST-- +Subtract 3 variables and print result +--FILE-- +<?php $a=27; $b=7; $c=10; $d=$a-$b-$c; echo $d?> +--EXPECT-- +10 diff --git a/code-samples/taskScheduler/example3/files/src/adv/010.phpt b/code-samples/taskScheduler/example3/files/src/adv/010.phpt new file mode 100644 index 0000000..9cdfece --- /dev/null +++ b/code-samples/taskScheduler/example3/files/src/adv/010.phpt @@ -0,0 +1,6 @@ +--TEST-- +Testing | and & operators +--FILE-- +<?php $a=8; $b=4; $c=8; echo $a|$b&$c?> +--EXPECT-- +8 diff --git a/code-samples/taskScheduler/example3/files/src/adv/011.phpt b/code-samples/taskScheduler/example3/files/src/adv/011.phpt new file mode 100644 index 0000000..68264af --- /dev/null +++ b/code-samples/taskScheduler/example3/files/src/adv/011.phpt @@ -0,0 +1,20 @@ +--TEST-- +Testing $argc and $argv handling (GET) +--SKIPIF-- +<?php if (php_sapi_name()=='cli') echo 'skip'; ?> +--INI-- +register_argc_argv=1 +--GET-- +ab+cd+ef+123+test +--FILE-- +<?php +for ($i=0; $i<$_SERVER['argc']; $i++) { + echo "$i: ".$_SERVER['argv'][$i]."\n"; +} +?> +--EXPECT-- +0: ab +1: cd +2: ef +3: 123 +4: test diff --git a/code-samples/taskScheduler/example3/files/src/adv/012.phpt b/code-samples/taskScheduler/example3/files/src/adv/012.phpt new file mode 100644 index 0000000..183eaae --- /dev/null +++ b/code-samples/taskScheduler/example3/files/src/adv/012.phpt @@ -0,0 +1,26 @@ +--TEST-- +Testing $argc and $argv handling (cli) +--SKIPIF-- +<?php if(php_sapi_name()!='cli') echo 'skip'; ?> +--INI-- +register_argc_argv=1 +variables_order=GPS +--ARGS-- +ab cd ef 123 test +--FILE-- +<?php + +$argc = $_SERVER['argc']; +$argv = $_SERVER['argv']; + +for ($i=1; $i<$argc; $i++) { + echo ($i-1).": ".$argv[$i]."\n"; +} + +?> +--EXPECT-- +0: ab +1: cd +2: ef +3: 123 +4: test diff --git a/code-samples/taskScheduler/example3/files/src/adv/013.phpt b/code-samples/taskScheduler/example3/files/src/adv/013.phpt new file mode 100644 index 0000000..38ebd9b --- /dev/null +++ b/code-samples/taskScheduler/example3/files/src/adv/013.phpt @@ -0,0 +1,15 @@ +--TEST-- +POST Method test and arrays +--SKIPIF-- +<?php if (php_sapi_name()=='cli') echo 'skip'; ?> +--POST-- +a[]=1 +--FILE-- +<?php +var_dump($_POST['a']); +?> +--EXPECT-- +array(1) { + [0]=> + unicode(1) "1" +} diff --git a/code-samples/taskScheduler/example3/files/src/adv/014.phpt b/code-samples/taskScheduler/example3/files/src/adv/014.phpt new file mode 100644 index 0000000..f7dd421 --- /dev/null +++ b/code-samples/taskScheduler/example3/files/src/adv/014.phpt @@ -0,0 +1,17 @@ +--TEST-- +POST Method test and arrays - 2 +--SKIPIF-- +<?php if (php_sapi_name()=='cli') echo 'skip'; ?> +--POST-- +a[]=1&a[]=1 +--FILE-- +<?php +var_dump($_POST['a']); +?> +--EXPECT-- +array(2) { + [0]=> + unicode(1) "1" + [1]=> + unicode(1) "1" +} diff --git a/code-samples/taskScheduler/example3/files/src/adv/015.phpt b/code-samples/taskScheduler/example3/files/src/adv/015.phpt new file mode 100644 index 0000000..a6ca5d6 --- /dev/null +++ b/code-samples/taskScheduler/example3/files/src/adv/015.phpt @@ -0,0 +1,15 @@ +--TEST-- +POST Method test and arrays - 3 +--SKIPIF-- +<?php if (php_sapi_name()=='cli') echo 'skip'; ?> +--POST-- +a[]=1&a[0]=5 +--FILE-- +<?php +var_dump($_POST['a']); +?> +--EXPECT-- +array(1) { + [0]=> + unicode(1) "5" +} diff --git a/code-samples/taskScheduler/example3/files/src/adv/016.phpt b/code-samples/taskScheduler/example3/files/src/adv/016.phpt new file mode 100644 index 0000000..c151634 --- /dev/null +++ b/code-samples/taskScheduler/example3/files/src/adv/016.phpt @@ -0,0 +1,17 @@ +--TEST-- +POST Method test and arrays - 4 +--SKIPIF-- +<?php if (php_sapi_name()=='cli') echo 'skip'; ?> +--POST-- +a[a]=1&a[b]=3 +--FILE-- +<?php +var_dump($_POST['a']); +?> +--EXPECT-- +array(2) { + [u"a"]=> + unicode(1) "1" + [u"b"]=> + unicode(1) "3" +} diff --git a/code-samples/taskScheduler/example3/files/src/adv/017.phpt b/code-samples/taskScheduler/example3/files/src/adv/017.phpt new file mode 100644 index 0000000..baac178 --- /dev/null +++ b/code-samples/taskScheduler/example3/files/src/adv/017.phpt @@ -0,0 +1,19 @@ +--TEST-- +POST Method test and arrays - 5 +--SKIPIF-- +<?php if (php_sapi_name()=='cli') echo 'skip'; ?> +--POST-- +a[]=1&a[a]=1&a[b]=3 +--FILE-- +<?php +var_dump($_POST['a']); +?> +--EXPECT-- +array(3) { + [0]=> + unicode(1) "1" + [u"a"]=> + unicode(1) "1" + [u"b"]=> + unicode(1) "3" +} diff --git a/code-samples/taskScheduler/example3/files/src/adv/018.phpt b/code-samples/taskScheduler/example3/files/src/adv/018.phpt new file mode 100644 index 0000000..da403b1 --- /dev/null +++ b/code-samples/taskScheduler/example3/files/src/adv/018.phpt @@ -0,0 +1,36 @@ +--TEST-- +POST Method test and arrays - 6 +--SKIPIF-- +<?php if (php_sapi_name()=='cli') echo 'skip'; ?> +--POST-- +a[][]=1&a[][]=3&b[a][b][c]=1&b[a][b][d]=1 +--FILE-- +<?php +var_dump($_POST['a']); +var_dump($_POST['b']); +?> +--EXPECT-- +array(2) { + [0]=> + array(1) { + [0]=> + unicode(1) "1" + } + [1]=> + array(1) { + [0]=> + unicode(1) "3" + } +} +array(1) { + [u"a"]=> + array(1) { + [u"b"]=> + array(2) { + [u"c"]=> + unicode(1) "1" + [u"d"]=> + unicode(1) "1" + } + } +} diff --git a/code-samples/taskScheduler/example3/files/src/adv/019.phpt b/code-samples/taskScheduler/example3/files/src/adv/019.phpt new file mode 100644 index 0000000..6deab51 --- /dev/null +++ b/code-samples/taskScheduler/example3/files/src/adv/019.phpt @@ -0,0 +1,19 @@ +--TEST-- +POST Method test and arrays - 7 +--SKIPIF-- +<?php if (php_sapi_name()=='cli') echo 'skip'; ?> +--POST-- +a[]=1&a[]]=3&a[[]=4 +--FILE-- +<?php +var_dump($_POST['a']); +?> +--EXPECT-- +array(3) { + [0]=> + unicode(1) "1" + [1]=> + unicode(1) "3" + [u"["]=> + unicode(1) "4" +} diff --git a/code-samples/taskScheduler/example3/files/src/adv/020.phpt b/code-samples/taskScheduler/example3/files/src/adv/020.phpt new file mode 100644 index 0000000..b105818 --- /dev/null +++ b/code-samples/taskScheduler/example3/files/src/adv/020.phpt @@ -0,0 +1,17 @@ +--TEST-- +POST Method test and arrays - 8 +--SKIPIF-- +<?php if (php_sapi_name()=='cli') echo 'skip'; ?> +--POST-- +a[a[]]=1&a[b[]]=3 +--FILE-- +<?php +var_dump($_POST['a']); +?> +--EXPECT-- +array(2) { + [u"a["]=> + unicode(1) "1" + [u"b["]=> + unicode(1) "3" +} diff --git a/code-samples/taskScheduler/example3/files/src/adv/022.phpt b/code-samples/taskScheduler/example3/files/src/adv/022.phpt new file mode 100644 index 0000000..9f21557 --- /dev/null +++ b/code-samples/taskScheduler/example3/files/src/adv/022.phpt @@ -0,0 +1,31 @@ +--TEST-- +Cookies test#1 +--COOKIE-- +cookie1=val1 ; cookie2=val2%20; cookie3=val 3.; cookie 4= value 4 %3B; cookie1=bogus; %20cookie1=ignore;+cookie1=ignore;cookie1;cookie 5=%20 value; cookie%206=þæö;cookie+7=;$cookie.8;cookie-9=1;;;- & % $cookie 10=10 +--FILE-- +<?php +var_dump($_COOKIE); +?> +--EXPECTF-- +array(10) { + [u"cookie1"]=> + unicode(0) "" + [u"cookie2"]=> + unicode(5) "val2 " + [u"cookie3"]=> + unicode(6) "val 3." + [u"cookie_4"]=> + unicode(10) " value 4 ;" + [u"cookie__5"]=> + unicode(7) " value" + [u"cookie_6"]=> + unicode(3) "%s" + [u"cookie_7"]=> + unicode(0) "" + [u"$cookie_8"]=> + unicode(0) "" + [u"cookie-9"]=> + unicode(1) "1" + [u"-_&_%_$cookie_10"]=> + unicode(2) "10" +} diff --git a/code-samples/taskScheduler/example3/files/src/adv/023.phpt b/code-samples/taskScheduler/example3/files/src/adv/023.phpt new file mode 100644 index 0000000..ece28b7 --- /dev/null +++ b/code-samples/taskScheduler/example3/files/src/adv/023.phpt @@ -0,0 +1,17 @@ +--TEST-- +Cookies test#2 +--COOKIE-- +c o o k i e=value; c o o k i e= v a l u e ;;c%20o+o k+i%20e=v;name="value","value",UEhQIQ==;UEhQIQ==foo +--FILE-- +<?php +var_dump($_COOKIE); +?> +--EXPECT-- +array(3) { + [u"c_o_o_k_i_e"]=> + unicode(1) "v" + [u"name"]=> + unicode(24) ""value","value",UEhQIQ==" + [u"UEhQIQ"]=> + unicode(4) "=foo" +} diff --git a/code-samples/taskScheduler/example3/files/src/adv/024.phpt b/code-samples/taskScheduler/example3/files/src/adv/024.phpt new file mode 100644 index 0000000..7484a11 --- /dev/null +++ b/code-samples/taskScheduler/example3/files/src/adv/024.phpt @@ -0,0 +1,30 @@ +--TEST-- +Test HTTP_RAW_POST_DATA creation +--INI-- +magic_quotes_gpc=0 +always_populate_raw_post_data=1 +--SKIPIF-- +<?php if (php_sapi_name()=='cli') echo 'skip'; ?> +--POST-- +a=ABC&y=XYZ&c[]=1&c[]=2&c[a]=3 +--FILE-- +<?php +var_dump($_POST, $HTTP_RAW_POST_DATA); +?> +--EXPECT-- +array(3) { + [u"a"]=> + unicode(3) "ABC" + [u"y"]=> + unicode(3) "XYZ" + [u"c"]=> + array(3) { + [0]=> + unicode(1) "1" + [1]=> + unicode(1) "2" + [u"a"]=> + unicode(1) "3" + } +} +unicode(30) "a=ABC&y=XYZ&c[]=1&c[]=2&c[a]=3" diff --git a/code-samples/taskScheduler/example3/files/src/adv/025.phpt b/code-samples/taskScheduler/example3/files/src/adv/025.phpt new file mode 100644 index 0000000..fea9468 --- /dev/null +++ b/code-samples/taskScheduler/example3/files/src/adv/025.phpt @@ -0,0 +1,23 @@ +--TEST-- +Test HTTP_RAW_POST_DATA with excessive post length +--INI-- +magic_quotes_gpc=0 +always_populate_raw_post_data=1 +post_max_size=1K +--SKIPIF-- +<?php if (php_sapi_name()=='cli') echo 'skip'; ?> +--POST-- +a=aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa +--FILE-- +<?php +var_dump($_POST, $HTTP_RAW_POST_DATA); +?> +--EXPECTF-- +Warning: Unknown: POST Content-Length of 2050 bytes exceeds the limit of 1024 bytes in Unknown on line 0 + +Warning: Cannot modify header information - headers already sent in Unknown on line 0 + +Notice: Undefined variable: HTTP_RAW_POST_DATA in %s on line %d +array(0) { +} +NULL diff --git a/code-samples/taskScheduler/example3/files/src/adv/026.phpt b/code-samples/taskScheduler/example3/files/src/adv/026.phpt new file mode 100644 index 0000000..6f90f6a --- /dev/null +++ b/code-samples/taskScheduler/example3/files/src/adv/026.phpt @@ -0,0 +1,18 @@ +--TEST-- +Registration of HTTP_RAW_POST_DATA due to unknown content-type +--INI-- +magic_quotes_gpc=0 +always_populate_raw_post_data=0 +--SKIPIF-- +<?php if (php_sapi_name()=='cli') echo 'skip'; ?> +--POST_RAW-- +Content-Type: unknown/type +a=1&b=ZYX +--FILE-- +<?php +var_dump($_POST, $HTTP_RAW_POST_DATA); +?> +--EXPECT-- +array(0) { +} +unicode(9) "a=1&b=ZYX" diff --git a/code-samples/taskScheduler/example3/files/src/adv/027.phpt b/code-samples/taskScheduler/example3/files/src/adv/027.phpt new file mode 100644 index 0000000..5f93d16 --- /dev/null +++ b/code-samples/taskScheduler/example3/files/src/adv/027.phpt @@ -0,0 +1,35 @@ +--TEST-- +Handling of max_input_nesting_level being reached +--INI-- +magic_quotes_gpc=0 +always_populate_raw_post_data=0 +display_errors=0 +max_input_nesting_level=10 +track_errors=1 +log_errors=0 +--SKIPIF-- +<?php if (php_sapi_name()=='cli') echo 'skip'; ?> +--POST-- +a=1&b=ZYX&c[][][][][][][][][][][][][][][][][][][][][][]=123&d=123&e[][]][]=3 +--FILE-- +<?php +var_dump($_POST, $php_errormsg); +?> +--EXPECT-- +array(4) { + [u"a"]=> + unicode(1) "1" + [u"b"]=> + unicode(3) "ZYX" + [u"d"]=> + unicode(3) "123" + [u"e"]=> + array(1) { + [0]=> + array(1) { + [0]=> + unicode(1) "3" + } + } +} +unicode(106) "Input variable nesting level exceeded 10. To increase the limit change max_input_nesting_level in php.ini." diff --git a/code-samples/taskScheduler/example3/files/src/basic/001.phpt b/code-samples/taskScheduler/example3/files/src/basic/001.phpt new file mode 100644 index 0000000..d0cc1ca --- /dev/null +++ b/code-samples/taskScheduler/example3/files/src/basic/001.phpt @@ -0,0 +1,6 @@ +--TEST-- +Trivial "Hello World" test +--FILE-- +<?php echo "Hello World"?> +--EXPECT-- +Hello World diff --git a/code-samples/taskScheduler/example3/files/src/basic/002.phpt b/code-samples/taskScheduler/example3/files/src/basic/002.phpt new file mode 100644 index 0000000..e9330c8 --- /dev/null +++ b/code-samples/taskScheduler/example3/files/src/basic/002.phpt @@ -0,0 +1,11 @@ +--TEST-- +Simple POST Method test +--SKIPIF-- +<?php if (php_sapi_name()=='cli') echo 'skip'; ?> +--POST-- +a=Hello+World +--FILE-- +<?php +echo $_POST['a']; ?> +--EXPECT-- +Hello World diff --git a/code-samples/taskScheduler/example3/files/src/basic/003.phpt b/code-samples/taskScheduler/example3/files/src/basic/003.phpt new file mode 100644 index 0000000..ae6603f --- /dev/null +++ b/code-samples/taskScheduler/example3/files/src/basic/003.phpt @@ -0,0 +1,14 @@ +--TEST-- +GET and POST Method combined +--SKIPIF-- +<?php if (php_sapi_name()=='cli') echo 'skip'; ?> +--POST-- +a=Hello+World +--GET-- +b=Hello+Again+World&c=Hi+Mom +--FILE-- +<?php +error_reporting(0); +echo "post-a=({$_POST['a']}) get-b=({$_GET['b']}) get-c=({$_GET['c']})"?> +--EXPECT-- +post-a=(Hello World) get-b=(Hello Again World) get-c=(Hi Mom) diff --git a/code-samples/taskScheduler/example3/files/src/basic/004.phpt b/code-samples/taskScheduler/example3/files/src/basic/004.phpt new file mode 100644 index 0000000..86bf431 --- /dev/null +++ b/code-samples/taskScheduler/example3/files/src/basic/004.phpt @@ -0,0 +1,12 @@ +--TEST-- +Two variables in POST data +--SKIPIF-- +<?php if (php_sapi_name()=='cli') echo 'skip'; ?> +--POST-- +a=Hello+World&b=Hello+Again+World +--FILE-- +<?php +error_reporting(0); +echo "{$_POST['a']} {$_POST['b']}" ?> +--EXPECT-- +Hello World Hello Again World diff --git a/code-samples/taskScheduler/example3/files/src/basic/005.phpt b/code-samples/taskScheduler/example3/files/src/basic/005.phpt new file mode 100644 index 0000000..aa1d199 --- /dev/null +++ b/code-samples/taskScheduler/example3/files/src/basic/005.phpt @@ -0,0 +1,12 @@ +--TEST-- +Three variables in POST data +--SKIPIF-- +<?php if (php_sapi_name()=='cli') echo 'skip'; ?> +--POST-- +a=Hello+World&b=Hello+Again+World&c=1 +--FILE-- +<?php +error_reporting(0); +echo "{$_POST['a']} {$_POST['b']} {$_POST['c']}"?> +--EXPECT-- +Hello World Hello Again World 1 diff --git a/code-samples/taskScheduler/example3/files/src/basic/006.phpt b/code-samples/taskScheduler/example3/files/src/basic/006.phpt new file mode 100644 index 0000000..c614cd9 --- /dev/null +++ b/code-samples/taskScheduler/example3/files/src/basic/006.phpt @@ -0,0 +1,6 @@ +--TEST-- +Add 3 variables together and print result +--FILE-- +<?php $a=1; $b=2; $c=3; $d=$a+$b+$c; echo $d?> +--EXPECT-- +6 diff --git a/code-samples/taskScheduler/example3/files/src/basic/007.phpt b/code-samples/taskScheduler/example3/files/src/basic/007.phpt new file mode 100644 index 0000000..dc808b7 --- /dev/null +++ b/code-samples/taskScheduler/example3/files/src/basic/007.phpt @@ -0,0 +1,6 @@ +--TEST-- +Multiply 3 variables and print result +--FILE-- +<?php $a=2; $b=4; $c=8; $d=$a*$b*$c; echo $d?> +--EXPECT-- +64 diff --git a/code-samples/taskScheduler/example3/files/src/func/001.phpt b/code-samples/taskScheduler/example3/files/src/func/001.phpt new file mode 100644 index 0000000..d080406 --- /dev/null +++ b/code-samples/taskScheduler/example3/files/src/func/001.phpt @@ -0,0 +1,6 @@ +--TEST-- +Strlen() function test +--FILE-- +<?php echo strlen("abcdef")?> +--EXPECT-- +6 diff --git a/code-samples/taskScheduler/example3/files/src/func/002.phpt b/code-samples/taskScheduler/example3/files/src/func/002.phpt new file mode 100644 index 0000000..cb35f92 --- /dev/null +++ b/code-samples/taskScheduler/example3/files/src/func/002.phpt @@ -0,0 +1,21 @@ +--TEST-- +Static variables in functions +--FILE-- +<?php +function blah() +{ + static $hey=0,$yo=0; + + echo "hey=".$hey++.", ",$yo--."\n"; +} + +blah(); +blah(); +blah(); +if (isset($hey) || isset($yo)) { + echo "Local variables became global :(\n"; +} +--EXPECT-- +hey=0, 0 +hey=1, -1 +hey=2, -2 diff --git a/code-samples/taskScheduler/example3/files/src/func/003.phpt b/code-samples/taskScheduler/example3/files/src/func/003.phpt new file mode 100644 index 0000000..d864c33 --- /dev/null +++ b/code-samples/taskScheduler/example3/files/src/func/003.phpt @@ -0,0 +1,290 @@ +--TEST-- +General function test +--FILE-- +<?php + +function a() +{ + echo "hey\n"; +} + +function b($i) +{ + echo "$i\n"; +} + + +function c($i,$j) +{ + echo "Counting from $i to $j\n"; + for ($k=$i; $k<=$j; $k++) { + echo "$k\n"; + } +} + + + +a(); +b("blah"); +a(); +b("blah","blah"); +c(7,14); + +a(); + + +function factorial($n) +{ + if ($n==0 || $n==1) { + return 1; + } else { + return factorial($n-1)*$n; + } +} + + +function factorial2($start, $n) +{ + if ($n<=$start) { + return $start; + } else { + return factorial2($start,$n-1)*$n; + } +} + + +for ($k=0; $k<10; $k++) { + for ($i=0; $i<=10; $i++) { + $n=factorial($i); + echo "factorial($i) = $n\n"; + } +} + + +echo "and now, from a function...\n"; + +function call_fact() +{ + echo "(it should break at 5...)\n"; + for ($i=0; $i<=10; $i++) { + if ($i == 5) break; + $n=factorial($i); + echo "factorial($i) = $n\n"; + } +} + +function return4() { return 4; } +function return7() { return 7; } + +for ($k=0; $k<10; $k++) { + call_fact(); +} + +echo "------\n"; +$result = factorial(factorial(3)); +echo "$result\n"; + +$result=factorial2(return4(),return7()); +echo "$result\n"; + +function andi($i, $j) +{ + for ($k=$i ; $k<=$j ; $k++) { + if ($k >5) continue; + echo "$k\n"; + } +} + +andi (3,10); +--EXPECT-- +hey +blah +hey +blah +Counting from 7 to 14 +7 +8 +9 +10 +11 +12 +13 +14 +hey +factorial(0) = 1 +factorial(1) = 1 +factorial(2) = 2 +factorial(3) = 6 +factorial(4) = 24 +factorial(5) = 120 +factorial(6) = 720 +factorial(7) = 5040 +factorial(8) = 40320 +factorial(9) = 362880 +factorial(10) = 3628800 +factorial(0) = 1 +factorial(1) = 1 +factorial(2) = 2 +factorial(3) = 6 +factorial(4) = 24 +factorial(5) = 120 +factorial(6) = 720 +factorial(7) = 5040 +factorial(8) = 40320 +factorial(9) = 362880 +factorial(10) = 3628800 +factorial(0) = 1 +factorial(1) = 1 +factorial(2) = 2 +factorial(3) = 6 +factorial(4) = 24 +factorial(5) = 120 +factorial(6) = 720 +factorial(7) = 5040 +factorial(8) = 40320 +factorial(9) = 362880 +factorial(10) = 3628800 +factorial(0) = 1 +factorial(1) = 1 +factorial(2) = 2 +factorial(3) = 6 +factorial(4) = 24 +factorial(5) = 120 +factorial(6) = 720 +factorial(7) = 5040 +factorial(8) = 40320 +factorial(9) = 362880 +factorial(10) = 3628800 +factorial(0) = 1 +factorial(1) = 1 +factorial(2) = 2 +factorial(3) = 6 +factorial(4) = 24 +factorial(5) = 120 +factorial(6) = 720 +factorial(7) = 5040 +factorial(8) = 40320 +factorial(9) = 362880 +factorial(10) = 3628800 +factorial(0) = 1 +factorial(1) = 1 +factorial(2) = 2 +factorial(3) = 6 +factorial(4) = 24 +factorial(5) = 120 +factorial(6) = 720 +factorial(7) = 5040 +factorial(8) = 40320 +factorial(9) = 362880 +factorial(10) = 3628800 +factorial(0) = 1 +factorial(1) = 1 +factorial(2) = 2 +factorial(3) = 6 +factorial(4) = 24 +factorial(5) = 120 +factorial(6) = 720 +factorial(7) = 5040 +factorial(8) = 40320 +factorial(9) = 362880 +factorial(10) = 3628800 +factorial(0) = 1 +factorial(1) = 1 +factorial(2) = 2 +factorial(3) = 6 +factorial(4) = 24 +factorial(5) = 120 +factorial(6) = 720 +factorial(7) = 5040 +factorial(8) = 40320 +factorial(9) = 362880 +factorial(10) = 3628800 +factorial(0) = 1 +factorial(1) = 1 +factorial(2) = 2 +factorial(3) = 6 +factorial(4) = 24 +factorial(5) = 120 +factorial(6) = 720 +factorial(7) = 5040 +factorial(8) = 40320 +factorial(9) = 362880 +factorial(10) = 3628800 +factorial(0) = 1 +factorial(1) = 1 +factorial(2) = 2 +factorial(3) = 6 +factorial(4) = 24 +factorial(5) = 120 +factorial(6) = 720 +factorial(7) = 5040 +factorial(8) = 40320 +factorial(9) = 362880 +factorial(10) = 3628800 +and now, from a function... +(it should break at 5...) +factorial(0) = 1 +factorial(1) = 1 +factorial(2) = 2 +factorial(3) = 6 +factorial(4) = 24 +(it should break at 5...) +factorial(0) = 1 +factorial(1) = 1 +factorial(2) = 2 +factorial(3) = 6 +factorial(4) = 24 +(it should break at 5...) +factorial(0) = 1 +factorial(1) = 1 +factorial(2) = 2 +factorial(3) = 6 +factorial(4) = 24 +(it should break at 5...) +factorial(0) = 1 +factorial(1) = 1 +factorial(2) = 2 +factorial(3) = 6 +factorial(4) = 24 +(it should break at 5...) +factorial(0) = 1 +factorial(1) = 1 +factorial(2) = 2 +factorial(3) = 6 +factorial(4) = 24 +(it should break at 5...) +factorial(0) = 1 +factorial(1) = 1 +factorial(2) = 2 +factorial(3) = 6 +factorial(4) = 24 +(it should break at 5...) +factorial(0) = 1 +factorial(1) = 1 +factorial(2) = 2 +factorial(3) = 6 +factorial(4) = 24 +(it should break at 5...) +factorial(0) = 1 +factorial(1) = 1 +factorial(2) = 2 +factorial(3) = 6 +factorial(4) = 24 +(it should break at 5...) +factorial(0) = 1 +factorial(1) = 1 +factorial(2) = 2 +factorial(3) = 6 +factorial(4) = 24 +(it should break at 5...) +factorial(0) = 1 +factorial(1) = 1 +factorial(2) = 2 +factorial(3) = 6 +factorial(4) = 24 +------ +720 +840 +3 +4 +5 diff --git a/code-samples/taskScheduler/example3/files/src/func/004.phpt b/code-samples/taskScheduler/example3/files/src/func/004.phpt new file mode 100644 index 0000000..1434297 --- /dev/null +++ b/code-samples/taskScheduler/example3/files/src/func/004.phpt @@ -0,0 +1,65 @@ +--TEST-- +General function test +--FILE-- +<?php + +echo "Before function declaration...\n"; + +function print_something_multiple_times($something,$times) +{ + echo "----\nIn function, printing the string \"$something\" $times times\n"; + for ($i=0; $i<$times; $i++) { + echo "$i) $something\n"; + } + echo "Done with function...\n-----\n"; +} + +function some_other_function() +{ + echo "This is some other function, to ensure more than just one function works fine...\n"; +} + + +echo "After function declaration...\n"; + +echo "Calling function for the first time...\n"; +print_something_multiple_times("This works!",10); +echo "Returned from function call...\n"; + +echo "Calling the function for the second time...\n"; +print_something_multiple_times("This like, really works and stuff...",3); +echo "Returned from function call...\n"; + +some_other_function(); + +?> +--EXPECT-- + +Before function declaration... +After function declaration... +Calling function for the first time... +---- +In function, printing the string "This works!" 10 times +0) This works! +1) This works! +2) This works! +3) This works! +4) This works! +5) This works! +6) This works! +7) This works! +8) This works! +9) This works! +Done with function... +----- +Returned from function call... +Calling the function for the second time... +---- +In function, printing the string "This like, really works and stuff..." 3 times +0) This like, really works and stuff... +1) This like, really works and stuff... +2) This like, really works and stuff... +Done with function... +----- +Returned from function call... +This is some other function, to ensure more than just one function works fine... diff --git a/code-samples/taskScheduler/example3/files/src/func/005.phpt b/code-samples/taskScheduler/example3/files/src/func/005.phpt new file mode 100644 index 0000000..3c8a6de --- /dev/null +++ b/code-samples/taskScheduler/example3/files/src/func/005.phpt @@ -0,0 +1,18 @@ +--TEST-- +Testing register_shutdown_function() +--FILE-- +<?php + +function foo() +{ + print "foo"; +} + +register_shutdown_function("foo"); + +print "foo() will be called on shutdown...\n"; + +?> +--EXPECT-- +foo() will be called on shutdown... +foo diff --git a/code-samples/taskScheduler/example3/files/src/func/005a.phpt b/code-samples/taskScheduler/example3/files/src/func/005a.phpt new file mode 100644 index 0000000..f7843e1 --- /dev/null +++ b/code-samples/taskScheduler/example3/files/src/func/005a.phpt @@ -0,0 +1,28 @@ +--TEST-- +Testing register_shutdown_function() with timeout. (Bug: #21513) +--FILE-- +<?php + +ini_set('display_errors', 0); + +echo "Start\n"; + +function boo() +{ + echo "Shutdown\n"; +} + +register_shutdown_function("boo"); + +/* not necessary, just to show the error sooner */ +set_time_limit(1); + +/* infinite loop to simulate long processing */ +for (;;) {} + +echo "End\n"; + +?> +--EXPECT-- +Start +Shutdown diff --git a/code-samples/taskScheduler/example3/files/src/func/006.phpt b/code-samples/taskScheduler/example3/files/src/func/006.phpt new file mode 100644 index 0000000..077b6f8 --- /dev/null +++ b/code-samples/taskScheduler/example3/files/src/func/006.phpt @@ -0,0 +1,26 @@ +--TEST-- +Output buffering tests +--INI-- +output_buffering=0 +output_handler= +zlib.output_compression=0 +zlib.output_handler= +--FILE-- +<?php +ob_start(); +echo ob_get_level(); +echo 'A'; + ob_start(); + echo ob_get_level(); + echo 'B'; + $b = ob_get_contents(); + ob_end_clean(); +$a = ob_get_contents(); +ob_end_clean(); + +var_dump( $b ); // 2B +var_dump( $a ); // 1A +?> +--EXPECT-- +string(2) "2B" +string(2) "1A" diff --git a/code-samples/taskScheduler/example3/files/src/func/007.phpt b/code-samples/taskScheduler/example3/files/src/func/007.phpt new file mode 100644 index 0000000..73aae2e --- /dev/null +++ b/code-samples/taskScheduler/example3/files/src/func/007.phpt @@ -0,0 +1,22 @@ +--TEST-- +INI functions test +--FILE-- +<?php + +$ini1 = ini_get('include_path'); +ini_set('include_path','ini_set_works'); +echo ini_get('include_path')."\n"; +ini_restore('include_path'); +$ini2 = ini_get('include_path'); + +if ($ini1 !== $ini2) { + echo "ini_restore() does not work.\n"; +} +else { + echo "ini_restore_works\n"; +} + +?> +--EXPECT-- +ini_set_works +ini_restore_works diff --git a/code-samples/taskScheduler/example3/files/src/func/008.phpt b/code-samples/taskScheduler/example3/files/src/func/008.phpt new file mode 100644 index 0000000..48098e1 --- /dev/null +++ b/code-samples/taskScheduler/example3/files/src/func/008.phpt @@ -0,0 +1,16 @@ +--TEST-- +Test for buffering in core functions with implicit flush off +--INI-- +implicit_flush=0 +--FILE-- +<?php +$res = var_export("foo1"); +echo "\n"; +$res = var_export("foo2", TRUE); +echo "\n"; +echo $res."\n"; +?> +--EXPECT-- +'foo1' + +'foo2' diff --git a/code-samples/taskScheduler/example3/files/src/func/009.phpt b/code-samples/taskScheduler/example3/files/src/func/009.phpt new file mode 100644 index 0000000..05b40e8 --- /dev/null +++ b/code-samples/taskScheduler/example3/files/src/func/009.phpt @@ -0,0 +1,16 @@ +--TEST-- +Test for buffering in core functions with implicit flush on +--INI-- +implicit_flush=1 +--FILE-- +<?php +$res = var_export("foo1"); +echo "\n"; +$res = var_export("foo2", TRUE); +echo "\n"; +echo $res."\n"; +?> +--EXPECT-- +'foo1' + +'foo2' diff --git a/code-samples/taskScheduler/example3/files/src/func/010.phpt b/code-samples/taskScheduler/example3/files/src/func/010.phpt new file mode 100644 index 0000000..ffc64a1 --- /dev/null +++ b/code-samples/taskScheduler/example3/files/src/func/010.phpt @@ -0,0 +1,73 @@ +--TEST-- +function with many parameters +--FILE-- +<?php + +// the stack size + some random constant +$boundary = 64*1024; +$limit = $boundary+42; + + +function test($a, $b) +{ + var_dump($a === $b); + test2($a,$b); +} + +function test2($a, $b) +{ + if ($a !== $b) { + var_dump("something went wrong: $a !== $b"); + } +} + + +// generate the function +$str = "<?php\nfunction x("; + +for($i=0; $i < $limit; ++$i) { + $str .= '$v'.dechex($i).($i===($limit-1) ? '' : ','); +} + +$str .= ') { + test($v42, \'42\'); + test(\'4000\', $v4000); + test2($v300, \'300\'); + test($v0, \'0\'); // first + test($v'.dechex($limit-1).", '".dechex($limit-1).'\'); // last + test($v'.dechex($boundary).", '".dechex($boundary).'\'); //boundary + test($v'.dechex($boundary+1).", '".dechex($boundary+1).'\'); //boundary+1 + test($v'.dechex($boundary-1).", '".dechex($boundary-1).'\'); //boundary-1 +}'; + +// generate the function call +$str .= "\n\nx("; + +for($i=0; $i< $limit; ++$i) { + $str .= "'".dechex($i)."'".($i===($limit-1) ? '' : ','); +} + +$str .= ");\n"; + +$filename = dirname(__FILE__).'/010-file.php'; +file_put_contents(dirname(__FILE__).'/010-file.php', $str); +unset($str); + +include($filename); + +echo "Done\n"; + +?> +--CLEAN-- +<?php +@unlink(dirname(__FILE__).'/010-file.php'); +?> +--EXPECT-- +bool(true) +bool(true) +bool(true) +bool(true) +bool(true) +bool(true) +bool(true) +Done diff --git a/code-samples/taskScheduler/example3/imgConverter/fileCreator.php b/code-samples/taskScheduler/example3/imgConverter/fileCreator.php new file mode 100644 index 0000000..16d4304 --- /dev/null +++ b/code-samples/taskScheduler/example3/imgConverter/fileCreator.php @@ -0,0 +1,48 @@ +<?php + +class fileCreator { + + + private $chars = array(); + private $buffer = ''; + + + public function __construct(array $chars) { + + $this->chars = $chars; + } + + + public function create() { + + for ($i=0; $i<sizeof($this->chars); $i++) { + + if ($this->chars[$i] != 255) { + + $this->buffer.= chr($this->chars[$i]); + } + } + } + + + public function getBufferString() { + + return $this->buffer; + } + + + public function write($file) { + + $f = fopen($file, 'w'); + + fwrite($f, $this->buffer); + + fclose($f); + } + + + + +} + +?> \ No newline at end of file diff --git a/code-samples/taskScheduler/example3/imgConverter/fileReader.php b/code-samples/taskScheduler/example3/imgConverter/fileReader.php new file mode 100644 index 0000000..a7a9034 --- /dev/null +++ b/code-samples/taskScheduler/example3/imgConverter/fileReader.php @@ -0,0 +1,54 @@ +<?php + +class fileReader { + + + private $file = NULL; + private $chars = array(); + + private $trimFile = false; + + + public function __construct($file) { + + $this->file = new SplFileInfo($file); + + if ($this->file->isFile() == false) + die($file.' is not a valid file'); + } + + + public function getAsciiChars() { + + return $this->chars; + } + + + public function setTrim($trim) { + + $this->trimFile = is_bool($trim) ? $trim : false; + } + + + public function read() { + + $lines = file($this->file->getPathname(), FILE_IGNORE_NEW_LINES); + + foreach ($lines as $line) { + + if ($this->trimFile) $line = trim($line); + + for ($i=0; $i<strlen($line); $i++) { + + $this->chars[] = ord($line{$i}); + } + + $this->chars[] = 10; // new line + } + } + + + +} + +?> \ No newline at end of file diff --git a/code-samples/taskScheduler/example3/imgConverter/imageCreator.php b/code-samples/taskScheduler/example3/imgConverter/imageCreator.php new file mode 100644 index 0000000..136c4e6 --- /dev/null +++ b/code-samples/taskScheduler/example3/imgConverter/imageCreator.php @@ -0,0 +1,133 @@ +<?php + + +class imageCreator { + + + private $chars = array(); + private $image = NULL; + private $size = 0; + + private $pixelGap = 2; + + + public function __construct(array $chars) { + + $this->chars = $chars; + } + + + public function draw() { + + $s = $this->size = ceil(sqrt(sizeof($this->chars)/3))*$this->pixelGap; + + $this->image = ImageCreateTrueColor($this->size-$this->pixelGap+1, $this->size-$this->pixelGap+1); + + $bg = ImageColorAllocate($this->image, 255, 255, 255); + + ImageFill($this->image, 0, 0, $bg); + ImageColorTransparent($this->image, $bg); + + $colors = array(); + + $x = 0; + $y = 0; + + for ($i=0; $i<sizeof($this->chars); $i+=3) { + + if ($i>0 && $x%$s==0) { + + $x = 0; + $y += $this->pixelGap ; + } + + $r = $this->chars[$i]; + $g = $this->chars[$i+1]; + $b = $this->chars[$i+2]; + + $v = $r.$g.$b; + + if (!isset($colors[$v])) + $colors[$v] = ImageColorAllocate($this->image , $r*2, $g*2, $b*2); + + ImageLine($this->image , $x, $y, $x, $y, $colors[$v]); + + $x += $this->pixelGap; + } + + // $this->quadSize(); + + // imageellipse($this->image, $size, $size, $size*2, $size*2, $bg); + } + + + public function quadSize() { + + $s = $this->size+$this->pixelGap-1; + + $img = ImageCreateTrueColor($s*2, $s*2); + + $bg = ImageColorAllocate($this->image , 255, 255, 255); + + ImageFill($img, 0, 0, $bg); + ImageColorTransparent($img, $bg); + + imagecopymerge($img, $this->image, $s, $s, 0, 0, $s, $s, 100); + + $tmp = ImageCreateTrueColor($s, $s); + + imagecopyresampled($tmp, $this->image, 0, 0, ($s-1), 0, $s, $s, 0-$s, $s); + imagecopymerge($img, $tmp, 0, $s, 0, 0, $s, $s, 100); + + imagecopyresampled($tmp, $this->image, 0, 0, 0, ($s-1), $s, $s, $s, 0-$s); + imagecopymerge($img, $tmp, $s, 0, 0, 0, $s, $s, 100); + + imagecopyresampled($tmp, $this->image, 0, 0, ($s-1), ($s-1), $s, $s, 0-$s, 0-$s); + imagecopymerge($img, $tmp, 0, 0, 0, 0, $s, $s, 100); + + $this->image = $img; + } + + + + public function nice() { + + $sum = array_sum($this->chars); + + $s = ceil(sqrt($sum)); + + $this->image = ImageCreateTrueColor(sizeof($this->chars)*2, 255); + + $bg = ImageColorAllocate($this->image, 255, 255, 255); + + ImageFill($this->image, 0, 0, $bg); + ImageColorTransparent($this->image, $bg); + + $colors = array(); + + for ($i=0; $i<sizeof($this->chars); $i++) { + + $v = $this->chars[$i]*2; + + if (!isset($colors[$v])) + $colors[$v] = ImageColorAllocate($this->image , $v, $v, $v); + + ImageLine($this->image , $i*2, 255, $i*2, 255-$v, $colors[$v]); + } + } + + + public function saveImage($name) { + + return ImagePNG($this->image, $name); + } + + public function setPixelGap($gap) { + + $this->pixelGap = is_numeric($gap) ? $gap+1 : 1; + } + +} + + +?> \ No newline at end of file diff --git a/code-samples/taskScheduler/example3/imgConverter/imageReader.php b/code-samples/taskScheduler/example3/imgConverter/imageReader.php new file mode 100644 index 0000000..53814da --- /dev/null +++ b/code-samples/taskScheduler/example3/imgConverter/imageReader.php @@ -0,0 +1,74 @@ +<?php + +class imageReader { + + + private $file = NULL; + private $chars = array(); + private $size = 0; + + private $pixelGap = 2; + + + public function __construct($file) { + + $this->file = new SplFileInfo($file); + + if ($this->file->isFile() == false) + throw Exception($file.' is not a valid file'); + + $info = getimagesize($this->file); + + if ($info[0] != $info[1]) + throw Exception($file.' has invalid dimensions'); + + $this->size = $info[0]; + + if ($info['mime'] != 'image/png') + throw Exception($file.' has to ba a png'); + } + + + public function read() { + + $img = ImageCreateFromPNG($this->file); + + $x = 0; + $y = 0; + + for ($i=0; $i<($this->size*$this->size); $i++) { + + if ($i>0 && $x%$this->size==0) { + + $x = 0; + $y += $this->pixelGap; + } + + $rgb = ImageColorAt($img, $x, $y); + + if ($rgb) { + + $this->chars[] = (($rgb >> 16) & 0xFF); + $this->chars[] = (($rgb >> 8) & 0xFF); + $this->chars[] = ($rgb & 0xFF); + } + + $x += $this->pixelGap; + } + } + + + public function getAsciiChars() { + + return $this->chars; + } + + public function setPixelGap($gap) { + + $this->pixelGap = is_numeric($gap) ? $gap+1 : 1; + } + + +} + +?> \ No newline at end of file diff --git a/code-samples/taskScheduler/example3/main.php b/code-samples/taskScheduler/example3/main.php new file mode 100644 index 0000000..73ba4cc --- /dev/null +++ b/code-samples/taskScheduler/example3/main.php @@ -0,0 +1,51 @@ +<?php + +include 'taskConvert.php'; + +include 'imgConverter/fileCreator.php'; +include 'imgConverter/fileReader.php'; +include 'imgConverter/imageCreator.php'; +include 'imgConverter/imageReader.php'; + + +function createTaskList() +{ + return readSource('example3/files'); +} + + +function readSource($base, $path=NULL) +{ + $files = array(); + + foreach (new DirectoryIterator($base.'/src/'.$path) as $file) { + + if ($file->isDot()) continue; + + $name = $file->getFileName(); + + if (substr($name,0,1) == '.') continue; + + if ($file->isDir()) { + + $dest = $base.'/dest'.$path.'/'.$name; + + if (!file_exists($dest)) { + + mkdir($dest); + chmod($dest, 0777); + } + + $files[] = readSource($base, $path.'/'.$name); + } + + elseif ($file->isFile()) { + + $files[] = new taskConvert($path.'/'.$name); + } + } + + return $files; +} + +?> \ No newline at end of file diff --git a/code-samples/taskScheduler/example3/taskConvert.php b/code-samples/taskScheduler/example3/taskConvert.php new file mode 100644 index 0000000..f61b45e --- /dev/null +++ b/code-samples/taskScheduler/example3/taskConvert.php @@ -0,0 +1,39 @@ +<?php + +class taskConvert extends task implements taskInterface +{ + private $sourceFile = NULL; + + + public function __construct($sourceFile) + { + $this->sourceFile = $sourceFile; + } + + + public function run() + { + if (is_null($this->sourceFile)) { + + $this->setState(self::FAIL); + $this->setMessage('no source file'); + return false; + } + + $reader = new fileReader('example3/files/src'.$this->sourceFile); + $reader->read(); + $chars = $reader->getAsciiChars(); + + $n = 'example3/files/dest'.$this->sourceFile.'.png'; + + $img = new imageCreator($chars); + $img->draw(); + $img->saveImage($n); + + return true; + } + +} + + +?> \ No newline at end of file diff --git a/code-samples/taskScheduler/run.php b/code-samples/taskScheduler/run.php new file mode 100644 index 0000000..be988d5 --- /dev/null +++ b/code-samples/taskScheduler/run.php @@ -0,0 +1,67 @@ +<?php + +include 'classes/taskScheduler.php'; +include 'classes/taskInterface.php'; +include 'classes/task.php'; + + +// logger + +date_default_timezone_set("Europe/Berlin"); + +function logg($msg) { + + $debug = false; + + if ($debug) { + + print '['.date('h:i:s').'] '.$msg."\n"; + flush(); + } +} + + +// arguments + +$argc = sizeof($argv); + +if ($argc == 2 || $argc == 3) { + + $src = $argv[1]; + $count = isset($argv[2]) ? $argv[2] : NULL; +} else { + + die("USAGE: php run.php example processCount\n"); +} + + +// include exmaple & create task-list + +$src = $src.'/main.php'; + +if (!file_exists($src)) { + + die("invalid example\n"); +} + +include $src; + +$taskList = createTaskList(); + + +// init scheduler + +$c = new taskScheduler(); +$c->setTaskList($taskList); +$c->setProcessCount($count); +$c->run(); +$c->printStatistic(); + +// var_dump($c->getTaskList()); + +$c->printFailedTasks(); + +exit(0); + +?> +
diff --git a/code-samples/taskScheduler/classes/task.php b/code-samples/taskScheduler/classes/task.php new file mode 100644 index 0000000..7712dd8 --- /dev/null +++ b/code-samples/taskScheduler/classes/task.php @@ -0,0 +1,48 @@ +<?php + +abstract class task +{ + const NOEX = 0; + const PASS = 1; + const FAIL = -1; + + private $state = self::NOEX; + private $index = NULL; + private $message = NULL; + + + public function setState($state) + { + $this->state = $state; + } + + public function getState() + { + return $this->state; + } + + + public function setMessage($msg) + { + $this->message = $msg; + } + + public function getMessage() + { + return $this->message; + } + + + public function setIndex($index) + { + $this->index = $index; + } + + public function getIndex() + { + return $this->index; + } + +} + +?> \ No newline at end of file diff --git a/code-samples/taskScheduler/classes/taskInterface.php b/code-samples/taskScheduler/classes/taskInterface.php new file mode 100644 index 0000000..a682db6 --- /dev/null +++ b/code-samples/taskScheduler/classes/taskInterface.php @@ -0,0 +1,8 @@ +<?php + +interface taskInterface +{ + public function run(); +} + +?> \ No newline at end of file diff --git a/code-samples/taskScheduler/classes/taskScheduler.php b/code-samples/taskScheduler/classes/taskScheduler.php new file mode 100644 index 0000000..d379ea6 --- /dev/null +++ b/code-samples/taskScheduler/classes/taskScheduler.php @@ -0,0 +1,475 @@ +<?php + +declare(ticks=true); + + +class taskScheduler +{ + const MSG_QUEUE_KEY = 1234; // id of the message-queue + const MSG_QUEUE_SIZE = 1024; // max-size of a single message + const KILL_CHILD = 'killBill'; // kill-signal to terminate a child + + private $taskList = array(); + private $processCount = NULL; + private $inputQueue = NULL; + private $pidStore = array(); + private $time = 0; + private $countPass = 0; + private $countFail = 0; + private $groupTasks = false; + + + /** + * the constructor + * + * @param array $taskList (optional) + * @param int $processCount (optional) + */ + public function __construct(array $taskList=NULL, $processCount=NULL) + { + if (is_array($taskList)) { + $this->setTaskList($taskList); + } + + $this->setProcessCount($processCount); + } + + + /** + * sets the task-list which has to be an array of task-objects. + * it's also possible to use a multidimensional array. in this case the + * tasks are distributed to the child-processes exactly in the way as they + * are grouped in the list. the first-level index strictly has to be + * numeric and continuous starting with zero. + * + * @param array $taskList + */ + public function setTaskList(array $taskList) + { + if (is_array($taskList[0])) { + $this->groupTasks = true; + $this->processCount = sizeof($taskList); + } + + $this->taskList = $taskList; + } + + + /** + * @return array $taskList + */ + public function getTaskList() + { + return $this->taskList; + } + + + /** + * sets the number of child-processes. + * in the case of using a multidimensional task-list this parameter is + * ignored and set to the number of task-groups. + * + * @param int $count + */ + public function setProcessCount($processCount) + { + if ($this->groupTasks !== true && is_numeric($processCount) && $processCount >= 0) { + $this->processCount = $processCount; + } + } + + + /** + * removes the used message-queues. + */ + private static function cleanUp() + { + @msg_remove_queue(msg_get_queue(self::MSG_QUEUE_KEY)); + @msg_remove_queue(msg_get_queue(self::MSG_QUEUE_KEY+1)); + logg("CLEAN UP"); + } + + + /** + * the signal-handler is called by the interrupt- or quit-signal and calls + * the cleanUp-method. + * + * @param int $signal + */ + public static function signalHandler($signal) + { + logg("SIGNAL: $signal"); + + switch($signal) { + + case SIGINT: + case SIGQUIT: + self::cleanUp(); + die("\n"); + break; + + default: + break; + } + } + + /** + * switch to run the classic- or the fork-mode + */ + public function run() + { + if ($this->processCount > 0) { + $this->runFork(); + } + else $this->runClassic(); + } + + + /** + * executes the tasks in a simple loop + * + * @return void + */ + private function runClassic() + { + $s = microtime(true); + + for ($i=0; $i<sizeof($this->taskList); $i++) { + + $task = $this->taskList[$i]; + + if ($task->run() === true) { + $task->setState(task::PASS); + $this->countPass++; + } else { + $task->setState(task::FAIL); + $this->countFail++; + } + + print "."; + flush(); + + $this->taskList[$i] = $task; + } + + $error = microtime(true); + + $this->time = round($error-$s,5); + + return; + } + + + /** + * starts the sender, the receiver and forks the defined + * number of child-processes. + * + * @return void + */ + private function runFork() + { + $startTime = microtime(true); + + // register signal-handler + pcntl_signal(SIGINT, "taskScheduler::signalHandler"); + pcntl_signal(SIGQUIT, "taskScheduler::signalHandler"); + + // trim the processCount if nesecarry + if (is_null($this->processCount) || $this->processCount > sizeof($this->taskList)) { + $this->processCount = sizeof($this->taskList); + } + + // fork the child-processes + for ($i=0; $i<=$this->processCount; $i++) { + + $this->pidStore[$i] = pcntl_fork(); + + switch ($this->pidStore[$i]) { + + case -1: // failure + die("could not fork"); + break; + + case 0: // child + if ($i==0) { + $this->sender(); + } else { + $cid = ($this->groupTasks == true) ? $i : NULL; + $this->child($cid); + } + break; + + default: // parent + break; + } + } + + // start the receiver + $this->receiver(); + + // wait until all child-processes are terminated + for ($i=0; $i<=$this->processCount; $i++) { + + pcntl_waitpid($this->pidStore[$i], $status); + logg("child $i terminated - status $status"); + } + + $endTime = microtime(true); + $this->time = round($endTime-$startTime,5); + + // remove the msg-queue + self::cleanUp(); + + logg("EXIT MAIN"); + return; + } + + + /** + * the receiver is listening to the result-queue and stores the incomming + * tasks back to the task-list. + * when finished it sends the kill-signal to all children and terminates + * itself. + * + * @return void + */ + private function receiver() + { + logg("RECEIVER START - ".sizeof($this->taskList)." tasks"); + + $resultQueue = msg_get_queue(self::MSG_QUEUE_KEY+1); + + $task = ''; + $type = 1; + + if ($this->groupTasks == true) { + $limit = 0; + foreach ($this->taskList as $list) { + $limit += sizeof($list); + } + } else { + $limit = sizeof($this->taskList); + } + + for ($i=0; $i<$limit; $i++) { + + if (msg_receive($resultQueue, 0, $type, self::MSG_QUEUE_SIZE, $task, true, NULL, $error)) { + + // check state + if ($task->getState() == task::PASS) { + $this->countPass++; + } else { + $this->countFail++; + } + + // store result + $index = $task->getIndex(); + + if ($this->groupTasks == true) { + $this->taskList[$type-2][$index] = $task; + logg("RECEIVER store task ".($type-1)."-$index"); + + } else { + $this->taskList[$index] = $task; + logg("RECEIVER store task $index"); + } + } + else logg("RECEIVER ERROR $error"); + } + + $inputQueue = msg_get_queue(self::MSG_QUEUE_KEY); + + for ($i=1; $i<=$this->processCount; $i++) { + + if (msg_send($inputQueue, $i, self::KILL_CHILD, true, true, $error)) { + + logg("RECEIVER send KILL_CHILD"); + } + else logg("RECEIVER ERROR $error"); + } + + logg("RECEIVER EXIT"); + return; + } + + + /** + * the sender is passes through the task-list and distributes the single + * tasks to the child-processes using the input-queue. + * when finished it terminates itself. + * + * @return void + */ + private function sender() + { + logg("SENDER START - ".sizeof($this->taskList)." tasks"); + + $this->inputQueue = msg_get_queue(self::MSG_QUEUE_KEY); + + for ($i=0; $i<sizeof($this->taskList); $i++) { + + if ($this->groupTasks == true) { + + for ($j=0; $j<sizeof($this->taskList[$i]); $j++) { + + $this->sendTask($this->taskList[$i][$j], $j, $i+1); + } + + } else { + + $this->sendTask($this->taskList[$i], $i); + } + } + + logg("SENDER EXIT"); + exit(0); + } + + + /** + * helper-class of sender. + * sends a task to a child-process using the input-queue. + * + * @param task $task the task to send + * @param int $index the task's index in the taskList + * @param int $type the message-type (default=1) + * @return void + */ + private function sendTask(task $task, $index, $type=1) + { + $task->setIndex($index); + + if (msg_send($this->inputQueue, $type, $task, true, true, $error)) { + + logg("SENDER send task $type - $index"); + } + else logg("SENDER ERROR $error"); + + return; + } + + + /** + * the child is listening to the input-queue and executes the incomming + * tasks. afterwards it setts the task-state and sends it back to the + * receiver by the result-queue. + * after receiving the kill-signal from the receiver it terminates itself. + * + * @param int $cid the child-id (default=NULL) + * @return void + */ + private function child($cid=NULL) + { + if (is_null($cid)) { + $cid = 0; + } + + logg("child $cid START"); + + $inputQueue = msg_get_queue(self::MSG_QUEUE_KEY); + $resultQueue = msg_get_queue(self::MSG_QUEUE_KEY+1); + + $type = 1; + + while (true) { + + if (msg_receive($inputQueue, $cid, $type, self::MSG_QUEUE_SIZE, $task, true, NULL, $error)) { + + if ($task == self::KILL_CHILD) + break; + + $index = $task->getIndex(); + + logg("child $cid - run task $index"); + + if ($task->run() === true) { + $task->setState(task::PASS); + } else { + $task->setState(task::FAIL); + } + + print "."; + flush(); + + if (msg_send($resultQueue, $cid+1, $task, true, true, $error)) { + + logg("child $cid - send task $index"); + } + else logg("child $cid ERROR $error"); + + } + else logg("child $cid ERROR $error"); + } + + logg("child $cid EXIT"); + exit(0); + } + + + /** + * prints the statistic + * + * @return void + */ + public function printStatistic() + { + print "\n----------------------------------------\n"; + + if ($this->groupTasks == true) { + + $count = 0; + foreach ($this->taskList as $list) { + $count += sizeof($list); + } + + print "Groups:\t\t".sizeof($this->taskList)."\n"; + print "Tasks:\t\t".$count."\n"; + + } else { + $count = sizeof($this->taskList); + print "Tasks:\t\t".$count."\n"; + } + + print "PASSED:\t\t".$this->countPass." (".round($this->countPass/$count*100,2)."%)\n"; + print "FAILED:\t\t".$this->countFail." (".round($this->countFail/$count*100,2)."%)\n"; + print "Processes:\t".$this->processCount."\n"; + print "Seconds:\t".$this->time."\n"; + + if ($this->processCount > 0) { + print "AVG sec/task:\t".round($this->time/$this->processCount,5)."\n"; + } + + print "----------------------------------------\n"; + flush(); + } + + + /** + * prints a overview of the faild tasks + * + * @return void + */ + public function printFailedTasks() + { + if ($this->countFail > 0) { + + print "FAILED TASKS"; + print "\n----------------------------------------\n"; + + for ($i=0; $i<sizeof($this->taskList); $i++) { + + $task = $this->taskList[$i]; + + if ($task->getState() == task::FAIL) { + print "Task $i: ".$task->getMessage()."\n"; + } + } + + print "----------------------------------------\n"; + flush(); + } + } + +} + +?> \ No newline at end of file diff --git a/code-samples/taskScheduler/example1/main.php b/code-samples/taskScheduler/example1/main.php new file mode 100644 index 0000000..2f3ae1d --- /dev/null +++ b/code-samples/taskScheduler/example1/main.php @@ -0,0 +1,25 @@ +<?php + +include 'taskCalculate.php'; + + +function createTaskList() +{ + $list = array(); + + for ($i=0; $i<rand(128,256); $i++) { + + $num = array(); + + for ($j=0; $j<rand(32,64); $j++) { + + $num[$j] = rand(0,9); + } + + $list[$i] = new taskCalculate($num); + } + + return $list; +} + +?> \ No newline at end of file diff --git a/code-samples/taskScheduler/example1/taskCalculate.php b/code-samples/taskScheduler/example1/taskCalculate.php new file mode 100644 index 0000000..114071d --- /dev/null +++ b/code-samples/taskScheduler/example1/taskCalculate.php @@ -0,0 +1,44 @@ +<?php + +class taskCalculate extends task implements taskInterface +{ + private $numbers = array(); + private $result = 0; + + + public function __construct(array $numbers) + { + $this->numbers = $numbers; + } + + + public function run() + { + $r = 0; + + foreach($this->numbers as $num) { + + $num = (int)$num; + $r += $num; + } + + if ($r%26 == 0) { + + $this->setMessage("just an example"); + return false; + } + + $this->result = $r; + return true; + } + + + public function getResult() + { + return $this->result; + } + +} + + +?> \ No newline at end of file diff --git a/code-samples/taskScheduler/example2/main.php b/code-samples/taskScheduler/example2/main.php new file mode 100644 index 0000000..f7599ae --- /dev/null +++ b/code-samples/taskScheduler/example2/main.php @@ -0,0 +1,18 @@ +<?php + +include 'taskSleep.php'; + + +function createTaskList() +{ + $list = array(); + + for ($i=0; $i<10; $i++) { + + $list[$i] = new taskSleep($i%3); + } + + return $list; +} + +?> \ No newline at end of file diff --git a/code-samples/taskScheduler/example2/taskSleep.php b/code-samples/taskScheduler/example2/taskSleep.php new file mode 100644 index 0000000..66e712f --- /dev/null +++ b/code-samples/taskScheduler/example2/taskSleep.php @@ -0,0 +1,22 @@ +<?php + +class taskSleep extends task implements taskInterface +{ + private $sleep = 0; + + + public function __construct($sleep) + { + $this->sleep = $sleep; + } + + + public function run() + { + sleep($this->sleep); + return true; + } +} + + +?> \ No newline at end of file diff --git a/code-samples/taskScheduler/example3/files/src/adv/008.phpt b/code-samples/taskScheduler/example3/files/src/adv/008.phpt new file mode 100644 index 0000000..511aef0 --- /dev/null +++ b/code-samples/taskScheduler/example3/files/src/adv/008.phpt @@ -0,0 +1,6 @@ +--TEST-- +Divide 3 variables and print result +--FILE-- +<?php $a=27; $b=3; $c=3; $d=$a/$b/$c; echo $d?> +--EXPECT-- +3 diff --git a/code-samples/taskScheduler/example3/files/src/adv/009.phpt b/code-samples/taskScheduler/example3/files/src/adv/009.phpt new file mode 100644 index 0000000..fefe529 --- /dev/null +++ b/code-samples/taskScheduler/example3/files/src/adv/009.phpt @@ -0,0 +1,6 @@ +--TEST-- +Subtract 3 variables and print result +--FILE-- +<?php $a=27; $b=7; $c=10; $d=$a-$b-$c; echo $d?> +--EXPECT-- +10 diff --git a/code-samples/taskScheduler/example3/files/src/adv/010.phpt b/code-samples/taskScheduler/example3/files/src/adv/010.phpt new file mode 100644 index 0000000..9cdfece --- /dev/null +++ b/code-samples/taskScheduler/example3/files/src/adv/010.phpt @@ -0,0 +1,6 @@ +--TEST-- +Testing | and & operators +--FILE-- +<?php $a=8; $b=4; $c=8; echo $a|$b&$c?> +--EXPECT-- +8 diff --git a/code-samples/taskScheduler/example3/files/src/adv/011.phpt b/code-samples/taskScheduler/example3/files/src/adv/011.phpt new file mode 100644 index 0000000..68264af --- /dev/null +++ b/code-samples/taskScheduler/example3/files/src/adv/011.phpt @@ -0,0 +1,20 @@ +--TEST-- +Testing $argc and $argv handling (GET) +--SKIPIF-- +<?php if (php_sapi_name()=='cli') echo 'skip'; ?> +--INI-- +register_argc_argv=1 +--GET-- +ab+cd+ef+123+test +--FILE-- +<?php +for ($i=0; $i<$_SERVER['argc']; $i++) { + echo "$i: ".$_SERVER['argv'][$i]."\n"; +} +?> +--EXPECT-- +0: ab +1: cd +2: ef +3: 123 +4: test diff --git a/code-samples/taskScheduler/example3/files/src/adv/012.phpt b/code-samples/taskScheduler/example3/files/src/adv/012.phpt new file mode 100644 index 0000000..183eaae --- /dev/null +++ b/code-samples/taskScheduler/example3/files/src/adv/012.phpt @@ -0,0 +1,26 @@ +--TEST-- +Testing $argc and $argv handling (cli) +--SKIPIF-- +<?php if(php_sapi_name()!='cli') echo 'skip'; ?> +--INI-- +register_argc_argv=1 +variables_order=GPS +--ARGS-- +ab cd ef 123 test +--FILE-- +<?php + +$argc = $_SERVER['argc']; +$argv = $_SERVER['argv']; + +for ($i=1; $i<$argc; $i++) { + echo ($i-1).": ".$argv[$i]."\n"; +} + +?> +--EXPECT-- +0: ab +1: cd +2: ef +3: 123 +4: test diff --git a/code-samples/taskScheduler/example3/files/src/adv/013.phpt b/code-samples/taskScheduler/example3/files/src/adv/013.phpt new file mode 100644 index 0000000..38ebd9b --- /dev/null +++ b/code-samples/taskScheduler/example3/files/src/adv/013.phpt @@ -0,0 +1,15 @@ +--TEST-- +POST Method test and arrays +--SKIPIF-- +<?php if (php_sapi_name()=='cli') echo 'skip'; ?> +--POST-- +a[]=1 +--FILE-- +<?php +var_dump($_POST['a']); +?> +--EXPECT-- +array(1) { + [0]=> + unicode(1) "1" +} diff --git a/code-samples/taskScheduler/example3/files/src/adv/014.phpt b/code-samples/taskScheduler/example3/files/src/adv/014.phpt new file mode 100644 index 0000000..f7dd421 --- /dev/null +++ b/code-samples/taskScheduler/example3/files/src/adv/014.phpt @@ -0,0 +1,17 @@ +--TEST-- +POST Method test and arrays - 2 +--SKIPIF-- +<?php if (php_sapi_name()=='cli') echo 'skip'; ?> +--POST-- +a[]=1&a[]=1 +--FILE-- +<?php +var_dump($_POST['a']); +?> +--EXPECT-- +array(2) { + [0]=> + unicode(1) "1" + [1]=> + unicode(1) "1" +} diff --git a/code-samples/taskScheduler/example3/files/src/adv/015.phpt b/code-samples/taskScheduler/example3/files/src/adv/015.phpt new file mode 100644 index 0000000..a6ca5d6 --- /dev/null +++ b/code-samples/taskScheduler/example3/files/src/adv/015.phpt @@ -0,0 +1,15 @@ +--TEST-- +POST Method test and arrays - 3 +--SKIPIF-- +<?php if (php_sapi_name()=='cli') echo 'skip'; ?> +--POST-- +a[]=1&a[0]=5 +--FILE-- +<?php +var_dump($_POST['a']); +?> +--EXPECT-- +array(1) { + [0]=> + unicode(1) "5" +} diff --git a/code-samples/taskScheduler/example3/files/src/adv/016.phpt b/code-samples/taskScheduler/example3/files/src/adv/016.phpt new file mode 100644 index 0000000..c151634 --- /dev/null +++ b/code-samples/taskScheduler/example3/files/src/adv/016.phpt @@ -0,0 +1,17 @@ +--TEST-- +POST Method test and arrays - 4 +--SKIPIF-- +<?php if (php_sapi_name()=='cli') echo 'skip'; ?> +--POST-- +a[a]=1&a[b]=3 +--FILE-- +<?php +var_dump($_POST['a']); +?> +--EXPECT-- +array(2) { + [u"a"]=> + unicode(1) "1" + [u"b"]=> + unicode(1) "3" +} diff --git a/code-samples/taskScheduler/example3/files/src/adv/017.phpt b/code-samples/taskScheduler/example3/files/src/adv/017.phpt new file mode 100644 index 0000000..baac178 --- /dev/null +++ b/code-samples/taskScheduler/example3/files/src/adv/017.phpt @@ -0,0 +1,19 @@ +--TEST-- +POST Method test and arrays - 5 +--SKIPIF-- +<?php if (php_sapi_name()=='cli') echo 'skip'; ?> +--POST-- +a[]=1&a[a]=1&a[b]=3 +--FILE-- +<?php +var_dump($_POST['a']); +?> +--EXPECT-- +array(3) { + [0]=> + unicode(1) "1" + [u"a"]=> + unicode(1) "1" + [u"b"]=> + unicode(1) "3" +} diff --git a/code-samples/taskScheduler/example3/files/src/adv/018.phpt b/code-samples/taskScheduler/example3/files/src/adv/018.phpt new file mode 100644 index 0000000..da403b1 --- /dev/null +++ b/code-samples/taskScheduler/example3/files/src/adv/018.phpt @@ -0,0 +1,36 @@ +--TEST-- +POST Method test and arrays - 6 +--SKIPIF-- +<?php if (php_sapi_name()=='cli') echo 'skip'; ?> +--POST-- +a[][]=1&a[][]=3&b[a][b][c]=1&b[a][b][d]=1 +--FILE-- +<?php +var_dump($_POST['a']); +var_dump($_POST['b']); +?> +--EXPECT-- +array(2) { + [0]=> + array(1) { + [0]=> + unicode(1) "1" + } + [1]=> + array(1) { + [0]=> + unicode(1) "3" + } +} +array(1) { + [u"a"]=> + array(1) { + [u"b"]=> + array(2) { + [u"c"]=> + unicode(1) "1" + [u"d"]=> + unicode(1) "1" + } + } +} diff --git a/code-samples/taskScheduler/example3/files/src/adv/019.phpt b/code-samples/taskScheduler/example3/files/src/adv/019.phpt new file mode 100644 index 0000000..6deab51 --- /dev/null +++ b/code-samples/taskScheduler/example3/files/src/adv/019.phpt @@ -0,0 +1,19 @@ +--TEST-- +POST Method test and arrays - 7 +--SKIPIF-- +<?php if (php_sapi_name()=='cli') echo 'skip'; ?> +--POST-- +a[]=1&a[]]=3&a[[]=4 +--FILE-- +<?php +var_dump($_POST['a']); +?> +--EXPECT-- +array(3) { + [0]=> + unicode(1) "1" + [1]=> + unicode(1) "3" + [u"["]=> + unicode(1) "4" +} diff --git a/code-samples/taskScheduler/example3/files/src/adv/020.phpt b/code-samples/taskScheduler/example3/files/src/adv/020.phpt new file mode 100644 index 0000000..b105818 --- /dev/null +++ b/code-samples/taskScheduler/example3/files/src/adv/020.phpt @@ -0,0 +1,17 @@ +--TEST-- +POST Method test and arrays - 8 +--SKIPIF-- +<?php if (php_sapi_name()=='cli') echo 'skip'; ?> +--POST-- +a[a[]]=1&a[b[]]=3 +--FILE-- +<?php +var_dump($_POST['a']); +?> +--EXPECT-- +array(2) { + [u"a["]=> + unicode(1) "1" + [u"b["]=> + unicode(1) "3" +} diff --git a/code-samples/taskScheduler/example3/files/src/adv/022.phpt b/code-samples/taskScheduler/example3/files/src/adv/022.phpt new file mode 100644 index 0000000..9f21557 --- /dev/null +++ b/code-samples/taskScheduler/example3/files/src/adv/022.phpt @@ -0,0 +1,31 @@ +--TEST-- +Cookies test#1 +--COOKIE-- +cookie1=val1 ; cookie2=val2%20; cookie3=val 3.; cookie 4= value 4 %3B; cookie1=bogus; %20cookie1=ignore;+cookie1=ignore;cookie1;cookie 5=%20 value; cookie%206=þæö;cookie+7=;$cookie.8;cookie-9=1;;;- & % $cookie 10=10 +--FILE-- +<?php +var_dump($_COOKIE); +?> +--EXPECTF-- +array(10) { + [u"cookie1"]=> + unicode(0) "" + [u"cookie2"]=> + unicode(5) "val2 " + [u"cookie3"]=> + unicode(6) "val 3." + [u"cookie_4"]=> + unicode(10) " value 4 ;" + [u"cookie__5"]=> + unicode(7) " value" + [u"cookie_6"]=> + unicode(3) "%s" + [u"cookie_7"]=> + unicode(0) "" + [u"$cookie_8"]=> + unicode(0) "" + [u"cookie-9"]=> + unicode(1) "1" + [u"-_&_%_$cookie_10"]=> + unicode(2) "10" +} diff --git a/code-samples/taskScheduler/example3/files/src/adv/023.phpt b/code-samples/taskScheduler/example3/files/src/adv/023.phpt new file mode 100644 index 0000000..ece28b7 --- /dev/null +++ b/code-samples/taskScheduler/example3/files/src/adv/023.phpt @@ -0,0 +1,17 @@ +--TEST-- +Cookies test#2 +--COOKIE-- +c o o k i e=value; c o o k i e= v a l u e ;;c%20o+o k+i%20e=v;name="value","value",UEhQIQ==;UEhQIQ==foo +--FILE-- +<?php +var_dump($_COOKIE); +?> +--EXPECT-- +array(3) { + [u"c_o_o_k_i_e"]=> + unicode(1) "v" + [u"name"]=> + unicode(24) ""value","value",UEhQIQ==" + [u"UEhQIQ"]=> + unicode(4) "=foo" +} diff --git a/code-samples/taskScheduler/example3/files/src/adv/024.phpt b/code-samples/taskScheduler/example3/files/src/adv/024.phpt new file mode 100644 index 0000000..7484a11 --- /dev/null +++ b/code-samples/taskScheduler/example3/files/src/adv/024.phpt @@ -0,0 +1,30 @@ +--TEST-- +Test HTTP_RAW_POST_DATA creation +--INI-- +magic_quotes_gpc=0 +always_populate_raw_post_data=1 +--SKIPIF-- +<?php if (php_sapi_name()=='cli') echo 'skip'; ?> +--POST-- +a=ABC&y=XYZ&c[]=1&c[]=2&c[a]=3 +--FILE-- +<?php +var_dump($_POST, $HTTP_RAW_POST_DATA); +?> +--EXPECT-- +array(3) { + [u"a"]=> + unicode(3) "ABC" + [u"y"]=> + unicode(3) "XYZ" + [u"c"]=> + array(3) { + [0]=> + unicode(1) "1" + [1]=> + unicode(1) "2" + [u"a"]=> + unicode(1) "3" + } +} +unicode(30) "a=ABC&y=XYZ&c[]=1&c[]=2&c[a]=3" diff --git a/code-samples/taskScheduler/example3/files/src/adv/025.phpt b/code-samples/taskScheduler/example3/files/src/adv/025.phpt new file mode 100644 index 0000000..fea9468 --- /dev/null +++ b/code-samples/taskScheduler/example3/files/src/adv/025.phpt @@ -0,0 +1,23 @@ +--TEST-- +Test HTTP_RAW_POST_DATA with excessive post length +--INI-- +magic_quotes_gpc=0 +always_populate_raw_post_data=1 +post_max_size=1K +--SKIPIF-- +<?php if (php_sapi_name()=='cli') echo 'skip'; ?> +--POST-- +a=aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa +--FILE-- +<?php +var_dump($_POST, $HTTP_RAW_POST_DATA); +?> +--EXPECTF-- +Warning: Unknown: POST Content-Length of 2050 bytes exceeds the limit of 1024 bytes in Unknown on line 0 + +Warning: Cannot modify header information - headers already sent in Unknown on line 0 + +Notice: Undefined variable: HTTP_RAW_POST_DATA in %s on line %d +array(0) { +} +NULL diff --git a/code-samples/taskScheduler/example3/files/src/adv/026.phpt b/code-samples/taskScheduler/example3/files/src/adv/026.phpt new file mode 100644 index 0000000..6f90f6a --- /dev/null +++ b/code-samples/taskScheduler/example3/files/src/adv/026.phpt @@ -0,0 +1,18 @@ +--TEST-- +Registration of HTTP_RAW_POST_DATA due to unknown content-type +--INI-- +magic_quotes_gpc=0 +always_populate_raw_post_data=0 +--SKIPIF-- +<?php if (php_sapi_name()=='cli') echo 'skip'; ?> +--POST_RAW-- +Content-Type: unknown/type +a=1&b=ZYX +--FILE-- +<?php +var_dump($_POST, $HTTP_RAW_POST_DATA); +?> +--EXPECT-- +array(0) { +} +unicode(9) "a=1&b=ZYX" diff --git a/code-samples/taskScheduler/example3/files/src/adv/027.phpt b/code-samples/taskScheduler/example3/files/src/adv/027.phpt new file mode 100644 index 0000000..5f93d16 --- /dev/null +++ b/code-samples/taskScheduler/example3/files/src/adv/027.phpt @@ -0,0 +1,35 @@ +--TEST-- +Handling of max_input_nesting_level being reached +--INI-- +magic_quotes_gpc=0 +always_populate_raw_post_data=0 +display_errors=0 +max_input_nesting_level=10 +track_errors=1 +log_errors=0 +--SKIPIF-- +<?php if (php_sapi_name()=='cli') echo 'skip'; ?> +--POST-- +a=1&b=ZYX&c[][][][][][][][][][][][][][][][][][][][][][]=123&d=123&e[][]][]=3 +--FILE-- +<?php +var_dump($_POST, $php_errormsg); +?> +--EXPECT-- +array(4) { + [u"a"]=> + unicode(1) "1" + [u"b"]=> + unicode(3) "ZYX" + [u"d"]=> + unicode(3) "123" + [u"e"]=> + array(1) { + [0]=> + array(1) { + [0]=> + unicode(1) "3" + } + } +} +unicode(106) "Input variable nesting level exceeded 10. To increase the limit change max_input_nesting_level in php.ini." diff --git a/code-samples/taskScheduler/example3/files/src/basic/001.phpt b/code-samples/taskScheduler/example3/files/src/basic/001.phpt new file mode 100644 index 0000000..d0cc1ca --- /dev/null +++ b/code-samples/taskScheduler/example3/files/src/basic/001.phpt @@ -0,0 +1,6 @@ +--TEST-- +Trivial "Hello World" test +--FILE-- +<?php echo "Hello World"?> +--EXPECT-- +Hello World diff --git a/code-samples/taskScheduler/example3/files/src/basic/002.phpt b/code-samples/taskScheduler/example3/files/src/basic/002.phpt new file mode 100644 index 0000000..e9330c8 --- /dev/null +++ b/code-samples/taskScheduler/example3/files/src/basic/002.phpt @@ -0,0 +1,11 @@ +--TEST-- +Simple POST Method test +--SKIPIF-- +<?php if (php_sapi_name()=='cli') echo 'skip'; ?> +--POST-- +a=Hello+World +--FILE-- +<?php +echo $_POST['a']; ?> +--EXPECT-- +Hello World diff --git a/code-samples/taskScheduler/example3/files/src/basic/003.phpt b/code-samples/taskScheduler/example3/files/src/basic/003.phpt new file mode 100644 index 0000000..ae6603f --- /dev/null +++ b/code-samples/taskScheduler/example3/files/src/basic/003.phpt @@ -0,0 +1,14 @@ +--TEST-- +GET and POST Method combined +--SKIPIF-- +<?php if (php_sapi_name()=='cli') echo 'skip'; ?> +--POST-- +a=Hello+World +--GET-- +b=Hello+Again+World&c=Hi+Mom +--FILE-- +<?php +error_reporting(0); +echo "post-a=({$_POST['a']}) get-b=({$_GET['b']}) get-c=({$_GET['c']})"?> +--EXPECT-- +post-a=(Hello World) get-b=(Hello Again World) get-c=(Hi Mom) diff --git a/code-samples/taskScheduler/example3/files/src/basic/004.phpt b/code-samples/taskScheduler/example3/files/src/basic/004.phpt new file mode 100644 index 0000000..86bf431 --- /dev/null +++ b/code-samples/taskScheduler/example3/files/src/basic/004.phpt @@ -0,0 +1,12 @@ +--TEST-- +Two variables in POST data +--SKIPIF-- +<?php if (php_sapi_name()=='cli') echo 'skip'; ?> +--POST-- +a=Hello+World&b=Hello+Again+World +--FILE-- +<?php +error_reporting(0); +echo "{$_POST['a']} {$_POST['b']}" ?> +--EXPECT-- +Hello World Hello Again World diff --git a/code-samples/taskScheduler/example3/files/src/basic/005.phpt b/code-samples/taskScheduler/example3/files/src/basic/005.phpt new file mode 100644 index 0000000..aa1d199 --- /dev/null +++ b/code-samples/taskScheduler/example3/files/src/basic/005.phpt @@ -0,0 +1,12 @@ +--TEST-- +Three variables in POST data +--SKIPIF-- +<?php if (php_sapi_name()=='cli') echo 'skip'; ?> +--POST-- +a=Hello+World&b=Hello+Again+World&c=1 +--FILE-- +<?php +error_reporting(0); +echo "{$_POST['a']} {$_POST['b']} {$_POST['c']}"?> +--EXPECT-- +Hello World Hello Again World 1 diff --git a/code-samples/taskScheduler/example3/files/src/basic/006.phpt b/code-samples/taskScheduler/example3/files/src/basic/006.phpt new file mode 100644 index 0000000..c614cd9 --- /dev/null +++ b/code-samples/taskScheduler/example3/files/src/basic/006.phpt @@ -0,0 +1,6 @@ +--TEST-- +Add 3 variables together and print result +--FILE-- +<?php $a=1; $b=2; $c=3; $d=$a+$b+$c; echo $d?> +--EXPECT-- +6 diff --git a/code-samples/taskScheduler/example3/files/src/basic/007.phpt b/code-samples/taskScheduler/example3/files/src/basic/007.phpt new file mode 100644 index 0000000..dc808b7 --- /dev/null +++ b/code-samples/taskScheduler/example3/files/src/basic/007.phpt @@ -0,0 +1,6 @@ +--TEST-- +Multiply 3 variables and print result +--FILE-- +<?php $a=2; $b=4; $c=8; $d=$a*$b*$c; echo $d?> +--EXPECT-- +64 diff --git a/code-samples/taskScheduler/example3/files/src/func/001.phpt b/code-samples/taskScheduler/example3/files/src/func/001.phpt new file mode 100644 index 0000000..d080406 --- /dev/null +++ b/code-samples/taskScheduler/example3/files/src/func/001.phpt @@ -0,0 +1,6 @@ +--TEST-- +Strlen() function test +--FILE-- +<?php echo strlen("abcdef")?> +--EXPECT-- +6 diff --git a/code-samples/taskScheduler/example3/files/src/func/002.phpt b/code-samples/taskScheduler/example3/files/src/func/002.phpt new file mode 100644 index 0000000..cb35f92 --- /dev/null +++ b/code-samples/taskScheduler/example3/files/src/func/002.phpt @@ -0,0 +1,21 @@ +--TEST-- +Static variables in functions +--FILE-- +<?php +function blah() +{ + static $hey=0,$yo=0; + + echo "hey=".$hey++.", ",$yo--."\n"; +} + +blah(); +blah(); +blah(); +if (isset($hey) || isset($yo)) { + echo "Local variables became global :(\n"; +} +--EXPECT-- +hey=0, 0 +hey=1, -1 +hey=2, -2 diff --git a/code-samples/taskScheduler/example3/files/src/func/003.phpt b/code-samples/taskScheduler/example3/files/src/func/003.phpt new file mode 100644 index 0000000..d864c33 --- /dev/null +++ b/code-samples/taskScheduler/example3/files/src/func/003.phpt @@ -0,0 +1,290 @@ +--TEST-- +General function test +--FILE-- +<?php + +function a() +{ + echo "hey\n"; +} + +function b($i) +{ + echo "$i\n"; +} + + +function c($i,$j) +{ + echo "Counting from $i to $j\n"; + for ($k=$i; $k<=$j; $k++) { + echo "$k\n"; + } +} + + + +a(); +b("blah"); +a(); +b("blah","blah"); +c(7,14); + +a(); + + +function factorial($n) +{ + if ($n==0 || $n==1) { + return 1; + } else { + return factorial($n-1)*$n; + } +} + + +function factorial2($start, $n) +{ + if ($n<=$start) { + return $start; + } else { + return factorial2($start,$n-1)*$n; + } +} + + +for ($k=0; $k<10; $k++) { + for ($i=0; $i<=10; $i++) { + $n=factorial($i); + echo "factorial($i) = $n\n"; + } +} + + +echo "and now, from a function...\n"; + +function call_fact() +{ + echo "(it should break at 5...)\n"; + for ($i=0; $i<=10; $i++) { + if ($i == 5) break; + $n=factorial($i); + echo "factorial($i) = $n\n"; + } +} + +function return4() { return 4; } +function return7() { return 7; } + +for ($k=0; $k<10; $k++) { + call_fact(); +} + +echo "------\n"; +$result = factorial(factorial(3)); +echo "$result\n"; + +$result=factorial2(return4(),return7()); +echo "$result\n"; + +function andi($i, $j) +{ + for ($k=$i ; $k<=$j ; $k++) { + if ($k >5) continue; + echo "$k\n"; + } +} + +andi (3,10); +--EXPECT-- +hey +blah +hey +blah +Counting from 7 to 14 +7 +8 +9 +10 +11 +12 +13 +14 +hey +factorial(0) = 1 +factorial(1) = 1 +factorial(2) = 2 +factorial(3) = 6 +factorial(4) = 24 +factorial(5) = 120 +factorial(6) = 720 +factorial(7) = 5040 +factorial(8) = 40320 +factorial(9) = 362880 +factorial(10) = 3628800 +factorial(0) = 1 +factorial(1) = 1 +factorial(2) = 2 +factorial(3) = 6 +factorial(4) = 24 +factorial(5) = 120 +factorial(6) = 720 +factorial(7) = 5040 +factorial(8) = 40320 +factorial(9) = 362880 +factorial(10) = 3628800 +factorial(0) = 1 +factorial(1) = 1 +factorial(2) = 2 +factorial(3) = 6 +factorial(4) = 24 +factorial(5) = 120 +factorial(6) = 720 +factorial(7) = 5040 +factorial(8) = 40320 +factorial(9) = 362880 +factorial(10) = 3628800 +factorial(0) = 1 +factorial(1) = 1 +factorial(2) = 2 +factorial(3) = 6 +factorial(4) = 24 +factorial(5) = 120 +factorial(6) = 720 +factorial(7) = 5040 +factorial(8) = 40320 +factorial(9) = 362880 +factorial(10) = 3628800 +factorial(0) = 1 +factorial(1) = 1 +factorial(2) = 2 +factorial(3) = 6 +factorial(4) = 24 +factorial(5) = 120 +factorial(6) = 720 +factorial(7) = 5040 +factorial(8) = 40320 +factorial(9) = 362880 +factorial(10) = 3628800 +factorial(0) = 1 +factorial(1) = 1 +factorial(2) = 2 +factorial(3) = 6 +factorial(4) = 24 +factorial(5) = 120 +factorial(6) = 720 +factorial(7) = 5040 +factorial(8) = 40320 +factorial(9) = 362880 +factorial(10) = 3628800 +factorial(0) = 1 +factorial(1) = 1 +factorial(2) = 2 +factorial(3) = 6 +factorial(4) = 24 +factorial(5) = 120 +factorial(6) = 720 +factorial(7) = 5040 +factorial(8) = 40320 +factorial(9) = 362880 +factorial(10) = 3628800 +factorial(0) = 1 +factorial(1) = 1 +factorial(2) = 2 +factorial(3) = 6 +factorial(4) = 24 +factorial(5) = 120 +factorial(6) = 720 +factorial(7) = 5040 +factorial(8) = 40320 +factorial(9) = 362880 +factorial(10) = 3628800 +factorial(0) = 1 +factorial(1) = 1 +factorial(2) = 2 +factorial(3) = 6 +factorial(4) = 24 +factorial(5) = 120 +factorial(6) = 720 +factorial(7) = 5040 +factorial(8) = 40320 +factorial(9) = 362880 +factorial(10) = 3628800 +factorial(0) = 1 +factorial(1) = 1 +factorial(2) = 2 +factorial(3) = 6 +factorial(4) = 24 +factorial(5) = 120 +factorial(6) = 720 +factorial(7) = 5040 +factorial(8) = 40320 +factorial(9) = 362880 +factorial(10) = 3628800 +and now, from a function... +(it should break at 5...) +factorial(0) = 1 +factorial(1) = 1 +factorial(2) = 2 +factorial(3) = 6 +factorial(4) = 24 +(it should break at 5...) +factorial(0) = 1 +factorial(1) = 1 +factorial(2) = 2 +factorial(3) = 6 +factorial(4) = 24 +(it should break at 5...) +factorial(0) = 1 +factorial(1) = 1 +factorial(2) = 2 +factorial(3) = 6 +factorial(4) = 24 +(it should break at 5...) +factorial(0) = 1 +factorial(1) = 1 +factorial(2) = 2 +factorial(3) = 6 +factorial(4) = 24 +(it should break at 5...) +factorial(0) = 1 +factorial(1) = 1 +factorial(2) = 2 +factorial(3) = 6 +factorial(4) = 24 +(it should break at 5...) +factorial(0) = 1 +factorial(1) = 1 +factorial(2) = 2 +factorial(3) = 6 +factorial(4) = 24 +(it should break at 5...) +factorial(0) = 1 +factorial(1) = 1 +factorial(2) = 2 +factorial(3) = 6 +factorial(4) = 24 +(it should break at 5...) +factorial(0) = 1 +factorial(1) = 1 +factorial(2) = 2 +factorial(3) = 6 +factorial(4) = 24 +(it should break at 5...) +factorial(0) = 1 +factorial(1) = 1 +factorial(2) = 2 +factorial(3) = 6 +factorial(4) = 24 +(it should break at 5...) +factorial(0) = 1 +factorial(1) = 1 +factorial(2) = 2 +factorial(3) = 6 +factorial(4) = 24 +------ +720 +840 +3 +4 +5 diff --git a/code-samples/taskScheduler/example3/files/src/func/004.phpt b/code-samples/taskScheduler/example3/files/src/func/004.phpt new file mode 100644 index 0000000..1434297 --- /dev/null +++ b/code-samples/taskScheduler/example3/files/src/func/004.phpt @@ -0,0 +1,65 @@ +--TEST-- +General function test +--FILE-- +<?php + +echo "Before function declaration...\n"; + +function print_something_multiple_times($something,$times) +{ + echo "----\nIn function, printing the string \"$something\" $times times\n"; + for ($i=0; $i<$times; $i++) { + echo "$i) $something\n"; + } + echo "Done with function...\n-----\n"; +} + +function some_other_function() +{ + echo "This is some other function, to ensure more than just one function works fine...\n"; +} + + +echo "After function declaration...\n"; + +echo "Calling function for the first time...\n"; +print_something_multiple_times("This works!",10); +echo "Returned from function call...\n"; + +echo "Calling the function for the second time...\n"; +print_something_multiple_times("This like, really works and stuff...",3); +echo "Returned from function call...\n"; + +some_other_function(); + +?> +--EXPECT-- + +Before function declaration... +After function declaration... +Calling function for the first time... +---- +In function, printing the string "This works!" 10 times +0) This works! +1) This works! +2) This works! +3) This works! +4) This works! +5) This works! +6) This works! +7) This works! +8) This works! +9) This works! +Done with function... +----- +Returned from function call... +Calling the function for the second time... +---- +In function, printing the string "This like, really works and stuff..." 3 times +0) This like, really works and stuff... +1) This like, really works and stuff... +2) This like, really works and stuff... +Done with function... +----- +Returned from function call... +This is some other function, to ensure more than just one function works fine... diff --git a/code-samples/taskScheduler/example3/files/src/func/005.phpt b/code-samples/taskScheduler/example3/files/src/func/005.phpt new file mode 100644 index 0000000..3c8a6de --- /dev/null +++ b/code-samples/taskScheduler/example3/files/src/func/005.phpt @@ -0,0 +1,18 @@ +--TEST-- +Testing register_shutdown_function() +--FILE-- +<?php + +function foo() +{ + print "foo"; +} + +register_shutdown_function("foo"); + +print "foo() will be called on shutdown...\n"; + +?> +--EXPECT-- +foo() will be called on shutdown... +foo diff --git a/code-samples/taskScheduler/example3/files/src/func/005a.phpt b/code-samples/taskScheduler/example3/files/src/func/005a.phpt new file mode 100644 index 0000000..f7843e1 --- /dev/null +++ b/code-samples/taskScheduler/example3/files/src/func/005a.phpt @@ -0,0 +1,28 @@ +--TEST-- +Testing register_shutdown_function() with timeout. (Bug: #21513) +--FILE-- +<?php + +ini_set('display_errors', 0); + +echo "Start\n"; + +function boo() +{ + echo "Shutdown\n"; +} + +register_shutdown_function("boo"); + +/* not necessary, just to show the error sooner */ +set_time_limit(1); + +/* infinite loop to simulate long processing */ +for (;;) {} + +echo "End\n"; + +?> +--EXPECT-- +Start +Shutdown diff --git a/code-samples/taskScheduler/example3/files/src/func/006.phpt b/code-samples/taskScheduler/example3/files/src/func/006.phpt new file mode 100644 index 0000000..077b6f8 --- /dev/null +++ b/code-samples/taskScheduler/example3/files/src/func/006.phpt @@ -0,0 +1,26 @@ +--TEST-- +Output buffering tests +--INI-- +output_buffering=0 +output_handler= +zlib.output_compression=0 +zlib.output_handler= +--FILE-- +<?php +ob_start(); +echo ob_get_level(); +echo 'A'; + ob_start(); + echo ob_get_level(); + echo 'B'; + $b = ob_get_contents(); + ob_end_clean(); +$a = ob_get_contents(); +ob_end_clean(); + +var_dump( $b ); // 2B +var_dump( $a ); // 1A +?> +--EXPECT-- +string(2) "2B" +string(2) "1A" diff --git a/code-samples/taskScheduler/example3/files/src/func/007.phpt b/code-samples/taskScheduler/example3/files/src/func/007.phpt new file mode 100644 index 0000000..73aae2e --- /dev/null +++ b/code-samples/taskScheduler/example3/files/src/func/007.phpt @@ -0,0 +1,22 @@ +--TEST-- +INI functions test +--FILE-- +<?php + +$ini1 = ini_get('include_path'); +ini_set('include_path','ini_set_works'); +echo ini_get('include_path')."\n"; +ini_restore('include_path'); +$ini2 = ini_get('include_path'); + +if ($ini1 !== $ini2) { + echo "ini_restore() does not work.\n"; +} +else { + echo "ini_restore_works\n"; +} + +?> +--EXPECT-- +ini_set_works +ini_restore_works diff --git a/code-samples/taskScheduler/example3/files/src/func/008.phpt b/code-samples/taskScheduler/example3/files/src/func/008.phpt new file mode 100644 index 0000000..48098e1 --- /dev/null +++ b/code-samples/taskScheduler/example3/files/src/func/008.phpt @@ -0,0 +1,16 @@ +--TEST-- +Test for buffering in core functions with implicit flush off +--INI-- +implicit_flush=0 +--FILE-- +<?php +$res = var_export("foo1"); +echo "\n"; +$res = var_export("foo2", TRUE); +echo "\n"; +echo $res."\n"; +?> +--EXPECT-- +'foo1' + +'foo2' diff --git a/code-samples/taskScheduler/example3/files/src/func/009.phpt b/code-samples/taskScheduler/example3/files/src/func/009.phpt new file mode 100644 index 0000000..05b40e8 --- /dev/null +++ b/code-samples/taskScheduler/example3/files/src/func/009.phpt @@ -0,0 +1,16 @@ +--TEST-- +Test for buffering in core functions with implicit flush on +--INI-- +implicit_flush=1 +--FILE-- +<?php +$res = var_export("foo1"); +echo "\n"; +$res = var_export("foo2", TRUE); +echo "\n"; +echo $res."\n"; +?> +--EXPECT-- +'foo1' + +'foo2' diff --git a/code-samples/taskScheduler/example3/files/src/func/010.phpt b/code-samples/taskScheduler/example3/files/src/func/010.phpt new file mode 100644 index 0000000..ffc64a1 --- /dev/null +++ b/code-samples/taskScheduler/example3/files/src/func/010.phpt @@ -0,0 +1,73 @@ +--TEST-- +function with many parameters +--FILE-- +<?php + +// the stack size + some random constant +$boundary = 64*1024; +$limit = $boundary+42; + + +function test($a, $b) +{ + var_dump($a === $b); + test2($a,$b); +} + +function test2($a, $b) +{ + if ($a !== $b) { + var_dump("something went wrong: $a !== $b"); + } +} + + +// generate the function +$str = "<?php\nfunction x("; + +for($i=0; $i < $limit; ++$i) { + $str .= '$v'.dechex($i).($i===($limit-1) ? '' : ','); +} + +$str .= ') { + test($v42, \'42\'); + test(\'4000\', $v4000); + test2($v300, \'300\'); + test($v0, \'0\'); // first + test($v'.dechex($limit-1).", '".dechex($limit-1).'\'); // last + test($v'.dechex($boundary).", '".dechex($boundary).'\'); //boundary + test($v'.dechex($boundary+1).", '".dechex($boundary+1).'\'); //boundary+1 + test($v'.dechex($boundary-1).", '".dechex($boundary-1).'\'); //boundary-1 +}'; + +// generate the function call +$str .= "\n\nx("; + +for($i=0; $i< $limit; ++$i) { + $str .= "'".dechex($i)."'".($i===($limit-1) ? '' : ','); +} + +$str .= ");\n"; + +$filename = dirname(__FILE__).'/010-file.php'; +file_put_contents(dirname(__FILE__).'/010-file.php', $str); +unset($str); + +include($filename); + +echo "Done\n"; + +?> +--CLEAN-- +<?php +@unlink(dirname(__FILE__).'/010-file.php'); +?> +--EXPECT-- +bool(true) +bool(true) +bool(true) +bool(true) +bool(true) +bool(true) +bool(true) +Done diff --git a/code-samples/taskScheduler/example3/imgConverter/fileCreator.php b/code-samples/taskScheduler/example3/imgConverter/fileCreator.php new file mode 100644 index 0000000..16d4304 --- /dev/null +++ b/code-samples/taskScheduler/example3/imgConverter/fileCreator.php @@ -0,0 +1,48 @@ +<?php + +class fileCreator { + + + private $chars = array(); + private $buffer = ''; + + + public function __construct(array $chars) { + + $this->chars = $chars; + } + + + public function create() { + + for ($i=0; $i<sizeof($this->chars); $i++) { + + if ($this->chars[$i] != 255) { + + $this->buffer.= chr($this->chars[$i]); + } + } + } + + + public function getBufferString() { + + return $this->buffer; + } + + + public function write($file) { + + $f = fopen($file, 'w'); + + fwrite($f, $this->buffer); + + fclose($f); + } + + + + +} + +?> \ No newline at end of file diff --git a/code-samples/taskScheduler/example3/imgConverter/fileReader.php b/code-samples/taskScheduler/example3/imgConverter/fileReader.php new file mode 100644 index 0000000..a7a9034 --- /dev/null +++ b/code-samples/taskScheduler/example3/imgConverter/fileReader.php @@ -0,0 +1,54 @@ +<?php + +class fileReader { + + + private $file = NULL; + private $chars = array(); + + private $trimFile = false; + + + public function __construct($file) { + + $this->file = new SplFileInfo($file); + + if ($this->file->isFile() == false) + die($file.' is not a valid file'); + } + + + public function getAsciiChars() { + + return $this->chars; + } + + + public function setTrim($trim) { + + $this->trimFile = is_bool($trim) ? $trim : false; + } + + + public function read() { + + $lines = file($this->file->getPathname(), FILE_IGNORE_NEW_LINES); + + foreach ($lines as $line) { + + if ($this->trimFile) $line = trim($line); + + for ($i=0; $i<strlen($line); $i++) { + + $this->chars[] = ord($line{$i}); + } + + $this->chars[] = 10; // new line + } + } + + + +} + +?> \ No newline at end of file diff --git a/code-samples/taskScheduler/example3/imgConverter/imageCreator.php b/code-samples/taskScheduler/example3/imgConverter/imageCreator.php new file mode 100644 index 0000000..136c4e6 --- /dev/null +++ b/code-samples/taskScheduler/example3/imgConverter/imageCreator.php @@ -0,0 +1,133 @@ +<?php + + +class imageCreator { + + + private $chars = array(); + private $image = NULL; + private $size = 0; + + private $pixelGap = 2; + + + public function __construct(array $chars) { + + $this->chars = $chars; + } + + + public function draw() { + + $s = $this->size = ceil(sqrt(sizeof($this->chars)/3))*$this->pixelGap; + + $this->image = ImageCreateTrueColor($this->size-$this->pixelGap+1, $this->size-$this->pixelGap+1); + + $bg = ImageColorAllocate($this->image, 255, 255, 255); + + ImageFill($this->image, 0, 0, $bg); + ImageColorTransparent($this->image, $bg); + + $colors = array(); + + $x = 0; + $y = 0; + + for ($i=0; $i<sizeof($this->chars); $i+=3) { + + if ($i>0 && $x%$s==0) { + + $x = 0; + $y += $this->pixelGap ; + } + + $r = $this->chars[$i]; + $g = $this->chars[$i+1]; + $b = $this->chars[$i+2]; + + $v = $r.$g.$b; + + if (!isset($colors[$v])) + $colors[$v] = ImageColorAllocate($this->image , $r*2, $g*2, $b*2); + + ImageLine($this->image , $x, $y, $x, $y, $colors[$v]); + + $x += $this->pixelGap; + } + + // $this->quadSize(); + + // imageellipse($this->image, $size, $size, $size*2, $size*2, $bg); + } + + + public function quadSize() { + + $s = $this->size+$this->pixelGap-1; + + $img = ImageCreateTrueColor($s*2, $s*2); + + $bg = ImageColorAllocate($this->image , 255, 255, 255); + + ImageFill($img, 0, 0, $bg); + ImageColorTransparent($img, $bg); + + imagecopymerge($img, $this->image, $s, $s, 0, 0, $s, $s, 100); + + $tmp = ImageCreateTrueColor($s, $s); + + imagecopyresampled($tmp, $this->image, 0, 0, ($s-1), 0, $s, $s, 0-$s, $s); + imagecopymerge($img, $tmp, 0, $s, 0, 0, $s, $s, 100); + + imagecopyresampled($tmp, $this->image, 0, 0, 0, ($s-1), $s, $s, $s, 0-$s); + imagecopymerge($img, $tmp, $s, 0, 0, 0, $s, $s, 100); + + imagecopyresampled($tmp, $this->image, 0, 0, ($s-1), ($s-1), $s, $s, 0-$s, 0-$s); + imagecopymerge($img, $tmp, 0, 0, 0, 0, $s, $s, 100); + + $this->image = $img; + } + + + + public function nice() { + + $sum = array_sum($this->chars); + + $s = ceil(sqrt($sum)); + + $this->image = ImageCreateTrueColor(sizeof($this->chars)*2, 255); + + $bg = ImageColorAllocate($this->image, 255, 255, 255); + + ImageFill($this->image, 0, 0, $bg); + ImageColorTransparent($this->image, $bg); + + $colors = array(); + + for ($i=0; $i<sizeof($this->chars); $i++) { + + $v = $this->chars[$i]*2; + + if (!isset($colors[$v])) + $colors[$v] = ImageColorAllocate($this->image , $v, $v, $v); + + ImageLine($this->image , $i*2, 255, $i*2, 255-$v, $colors[$v]); + } + } + + + public function saveImage($name) { + + return ImagePNG($this->image, $name); + } + + public function setPixelGap($gap) { + + $this->pixelGap = is_numeric($gap) ? $gap+1 : 1; + } + +} + + +?> \ No newline at end of file diff --git a/code-samples/taskScheduler/example3/imgConverter/imageReader.php b/code-samples/taskScheduler/example3/imgConverter/imageReader.php new file mode 100644 index 0000000..53814da --- /dev/null +++ b/code-samples/taskScheduler/example3/imgConverter/imageReader.php @@ -0,0 +1,74 @@ +<?php + +class imageReader { + + + private $file = NULL; + private $chars = array(); + private $size = 0; + + private $pixelGap = 2; + + + public function __construct($file) { + + $this->file = new SplFileInfo($file); + + if ($this->file->isFile() == false) + throw Exception($file.' is not a valid file'); + + $info = getimagesize($this->file); + + if ($info[0] != $info[1]) + throw Exception($file.' has invalid dimensions'); + + $this->size = $info[0]; + + if ($info['mime'] != 'image/png') + throw Exception($file.' has to ba a png'); + } + + + public function read() { + + $img = ImageCreateFromPNG($this->file); + + $x = 0; + $y = 0; + + for ($i=0; $i<($this->size*$this->size); $i++) { + + if ($i>0 && $x%$this->size==0) { + + $x = 0; + $y += $this->pixelGap; + } + + $rgb = ImageColorAt($img, $x, $y); + + if ($rgb) { + + $this->chars[] = (($rgb >> 16) & 0xFF); + $this->chars[] = (($rgb >> 8) & 0xFF); + $this->chars[] = ($rgb & 0xFF); + } + + $x += $this->pixelGap; + } + } + + + public function getAsciiChars() { + + return $this->chars; + } + + public function setPixelGap($gap) { + + $this->pixelGap = is_numeric($gap) ? $gap+1 : 1; + } + + +} + +?> \ No newline at end of file diff --git a/code-samples/taskScheduler/example3/main.php b/code-samples/taskScheduler/example3/main.php new file mode 100644 index 0000000..73ba4cc --- /dev/null +++ b/code-samples/taskScheduler/example3/main.php @@ -0,0 +1,51 @@ +<?php + +include 'taskConvert.php'; + +include 'imgConverter/fileCreator.php'; +include 'imgConverter/fileReader.php'; +include 'imgConverter/imageCreator.php'; +include 'imgConverter/imageReader.php'; + + +function createTaskList() +{ + return readSource('example3/files'); +} + + +function readSource($base, $path=NULL) +{ + $files = array(); + + foreach (new DirectoryIterator($base.'/src/'.$path) as $file) { + + if ($file->isDot()) continue; + + $name = $file->getFileName(); + + if (substr($name,0,1) == '.') continue; + + if ($file->isDir()) { + + $dest = $base.'/dest'.$path.'/'.$name; + + if (!file_exists($dest)) { + + mkdir($dest); + chmod($dest, 0777); + } + + $files[] = readSource($base, $path.'/'.$name); + } + + elseif ($file->isFile()) { + + $files[] = new taskConvert($path.'/'.$name); + } + } + + return $files; +} + +?> \ No newline at end of file diff --git a/code-samples/taskScheduler/example3/taskConvert.php b/code-samples/taskScheduler/example3/taskConvert.php new file mode 100644 index 0000000..f61b45e --- /dev/null +++ b/code-samples/taskScheduler/example3/taskConvert.php @@ -0,0 +1,39 @@ +<?php + +class taskConvert extends task implements taskInterface +{ + private $sourceFile = NULL; + + + public function __construct($sourceFile) + { + $this->sourceFile = $sourceFile; + } + + + public function run() + { + if (is_null($this->sourceFile)) { + + $this->setState(self::FAIL); + $this->setMessage('no source file'); + return false; + } + + $reader = new fileReader('example3/files/src'.$this->sourceFile); + $reader->read(); + $chars = $reader->getAsciiChars(); + + $n = 'example3/files/dest'.$this->sourceFile.'.png'; + + $img = new imageCreator($chars); + $img->draw(); + $img->saveImage($n); + + return true; + } + +} + + +?> \ No newline at end of file diff --git a/code-samples/taskScheduler/run.php b/code-samples/taskScheduler/run.php new file mode 100644 index 0000000..be988d5 --- /dev/null +++ b/code-samples/taskScheduler/run.php @@ -0,0 +1,67 @@ +<?php + +include 'classes/taskScheduler.php'; +include 'classes/taskInterface.php'; +include 'classes/task.php'; + + +// logger + +date_default_timezone_set("Europe/Berlin"); + +function logg($msg) { + + $debug = false; + + if ($debug) { + + print '['.date('h:i:s').'] '.$msg."\n"; + flush(); + } +} + + +// arguments + +$argc = sizeof($argv); + +if ($argc == 2 || $argc == 3) { + + $src = $argv[1]; + $count = isset($argv[2]) ? $argv[2] : NULL; +} else { + + die("USAGE: php run.php example processCount\n"); +} + + +// include exmaple & create task-list + +$src = $src.'/main.php'; + +if (!file_exists($src)) { + + die("invalid example\n"); +} + +include $src; + +$taskList = createTaskList(); + + +// init scheduler + +$c = new taskScheduler(); +$c->setTaskList($taskList); +$c->setProcessCount($count); +$c->run(); +$c->printStatistic(); + +// var_dump($c->getTaskList()); + +$c->printFailedTasks(); + +exit(0); + +?> +