Current File : /home/mmdealscpanel/yummmdeals.com/alt-php84-pecl-gearman_2.1.4-1.el8.tar
tests/gearman_client_016.phpt000064400000003126150414423320012141 0ustar00--TEST--
GearmanClient::doStatus(), gearman_client_do_status()
--SKIPIF--
<?php if (!extension_loaded("gearman")) print "skip";
require_once('skipifconnect.inc');
?>
--FILE--
<?php 

$job_name = uniqid();

$client = new GearmanClient();
$client->addOptions(GEARMAN_CLIENT_NON_BLOCKING);
$client->addServer('localhost', 4730);

# Note: Still need to figure out why doNormal is blocking despite
# GEARMAN_CLIENT_NON_BLOCKING
#$job_handle = $client->doNormal($job_name . "_OO", "test_doStatus");
list($numerator, $denominator) = $client->doStatus();

print "GearmanClient::doStatus() (OO): " . PHP_EOL
	. "  Numerator is 0: " . ($numerator == 0 ? 'Success' : 'Failure') .
	PHP_EOL
	. "  Denominator is 0: " . ($denominator == 0 ? 'Success' : 'Failure') .
	PHP_EOL;

$client2 = gearman_client_create();
gearman_client_add_options($client2, GEARMAN_CLIENT_NON_BLOCKING);
gearman_client_add_server($client2, 'localhost', 4730);

# Note: Still need to figure out why doNormal is blocking despite
# GEARMAN_CLIENT_NON_BLOCKING
#$job_handle = gearman_client_do_normal->($client2, $job_name . "_procedural", "test_doStatus");
list($numerator, $denominator) = gearman_client_do_status($client2);

print "gearman_client_do_status() (Procedural): " . PHP_EOL
	. "  Numerator is 0: " . ($numerator == 0 ? 'Success' : 'Failure') .
	PHP_EOL
	. "  Denominator is 0: " . ($denominator == 0 ? 'Success' : 'Failure') .
	PHP_EOL;

print "OK";
?>
--EXPECT--
GearmanClient::doStatus() (OO): 
  Numerator is 0: Success
  Denominator is 0: Success
gearman_client_do_status() (Procedural): 
  Numerator is 0: Success
  Denominator is 0: Success
OK
tests/gearman_task_004.phpt000064400000004131150414423330011620 0ustar00--TEST--
GearmanTask::is_known(), gearman_task_is_known(),
GearmanTask::is_running(), gearman_task_is_running(),
GearmanTask::numerator(), gearman_task_numerator(),
GearmanTask::denominator(), gearman_task_denominator()
--SKIPIF--
<?php if (!extension_loaded("gearman")) print "skip";
require_once('skipifconnect.inc');
?>
--FILE--
<?php 

$client = new GearmanClient();
$client->addServer('localhost', 4730);
$client->setCreatedCallback(function ($task) {
	print "GearmanTask::isKnown (OO): "
		. ($task->isKnown() === true ? 'Success' : 'Failure') . PHP_EOL;
	print "GearmanTask::isRunning (OO): "
		. ($task->isRunning() === false ? 'Success' : 'Failure') . PHP_EOL;
	print "GearmanTask::taskNumerator (OO): "
		. ($task->taskNumerator() == 0 ? 'Success' : 'Failure') . PHP_EOL;
	print "GearmanTask::taskDenominator (OO): "
		. ($task->taskDenominator() == 0 ? 'Success' : 'Failure') . PHP_EOL;
});

$client->addTaskBackground("GearmanTaskFunction", "normal");
$client->runTasks();


$client2 = gearman_client_create();
gearman_client_add_server($client2, 'localhost', 4730);
gearman_client_set_created_callback($client2, function ($task) {
	print "gearman_task_is_known (Procedural): "
		. (gearman_task_is_known($task) === true ? 'Success' : 'Failure') . PHP_EOL;
	print "gearman_task_is_running (Procedural): "
		. (gearman_task_is_running($task) === false ? 'Success' : 'Failure') . PHP_EOL;
	print "gearman_task_numerator (Procedural): "
		. (gearman_task_numerator($task) == 0 ? 'Success' : 'Failure') . PHP_EOL;
	print "gearman_task_denominator (Procedural): "
		. (gearman_task_denominator($task) == 0 ? 'Success' : 'Failure') . PHP_EOL;
});
gearman_client_add_task_background($client2, "GearmanTaskFunction2", "normal");
gearman_client_run_tasks($client2);

print "OK";
?>
--EXPECT--
GearmanTask::isKnown (OO): Success
GearmanTask::isRunning (OO): Success
GearmanTask::taskNumerator (OO): Success
GearmanTask::taskDenominator (OO): Success
gearman_task_is_known (Procedural): Success
gearman_task_is_running (Procedural): Success
gearman_task_numerator (Procedural): Success
gearman_task_denominator (Procedural): Success
OK
tests/gearman_client_008.phpt000064400000002230150414423330012136 0ustar00--TEST--
GearmanClient::removeOptions(), gearman_client_remove_options()
--SKIPIF--
<?php if (!extension_loaded("gearman")) print "skip"; ?>
--FILE--
<?php 

$client = new GearmanClient();
$client->setOptions(32);
print "GearmanClient::options (OO): " . $client->options() . PHP_EOL;
print "GearmanClient::removeOptions (OO): " . ($client->removeOptions(GEARMAN_CLIENT_FREE_TASKS) ? 'Success' : 'Failure') . PHP_EOL;
print "GearmanClient::options (OO): " . $client->options() . PHP_EOL;

$client2 = gearman_client_create();
gearman_client_set_options($client2, 32);
print "gearman_client_options (Procedural): " . gearman_client_options($client2) . PHP_EOL;
print "gearman_client_remove_options (Procedural): " . (gearman_client_remove_options($client2, GEARMAN_CLIENT_FREE_TASKS) ? 'Success' : 'Failure') . PHP_EOL;
print "gearman_client_options (Procedural): " . gearman_client_options($client2) . PHP_EOL;

print "OK";
?>
--EXPECT--
GearmanClient::options (OO): 32
GearmanClient::removeOptions (OO): Success
GearmanClient::options (OO): 0
gearman_client_options (Procedural): 32
gearman_client_remove_options (Procedural): Success
gearman_client_options (Procedural): 0
OK
tests/gearman_job_003.phpt000064400000000446150414423330011434 0ustar00--TEST--
unserialize(serialize(GearmanJob))
--SKIPIF--
<?php if (!extension_loaded("gearman")) print "skip"; ?>
--FILE--
<?php

$i = 0;
while ($i <= 5) {
    echo $i;
    $job = new GearmanJob();
    unserialize(serialize($job));
    $i++;
}
print PHP_EOL;

print "OK";
?>
--EXPECT--
012345
OK
tests/gearman_worker_011.phpt000064400000000573150414423330012173 0ustar00--TEST--
gearman_worker_wait()
--SKIPIF--
<?php if (!extension_loaded("gearman")) print "skip";
require_once('skipifconnect.inc');
?>
--FILE--
<?php 

$host = 'localhost';
$port = 4730;

$worker = new GearmanWorker();
$worker->addServer($host, $port);
$worker->setTimeout(1);
/*
Still need to figure out how to test wait here...
$worker->wait();
*/

print "OK";
?>
--EXPECT--
OK
tests/gearman_job_integration_test_010.phpt000064400000003031150414423330015065 0ustar00--TEST--
Test GearmanJob::workload(), GearmanJob::workloadSize()
--SKIPIF--
<?php
require_once('skipif.inc');
require_once('skipifconnect.inc');
?>
--FILE--
<?php
require_once('connect.inc');

print "Start" . PHP_EOL;

$job_name = uniqid();

$pid = pcntl_fork();
if ($pid == -1) {
    die("Could not fork");
} else if ($pid > 0) {
    // Parent. This is the worker
    $worker = new GearmanWorker();
    $worker->addServer($host, $port);
    $worker->addFunction(
        $job_name,
        function($job, $data) {
            print "GearmanJob::workload (OO): "
                . $job->workload()
                . PHP_EOL;

            print "GearmanJob::workloadSize (OO): "
                . $job->workloadSize()
                . PHP_EOL;
            }
    );

    $worker->work();

    $worker->unregister($job_name);

    // Wait for child
    $exit_status = 0;
    if (pcntl_wait($exit_status) <= 0) {
        print "pcntl_wait exited with error" . PHP_EOL;
    } else if (!pcntl_wifexited($exit_status)) {
        print "child exited with error" . PHP_EOL;
    }
} else {
    //Child. This is the client. Don't echo anything here
    $client = new GearmanClient();
    if ($client->addServer($host, $port) !== true) {
        exit(1); // error
    };

    $tasks = [];
    $tasks[] = $client->addTask($job_name, "normal");
    $client->runTasks();
    if ($client->returnCode() != GEARMAN_SUCCESS) {
        exit(2); // error
    }
    exit(0);
}

print "Done";
--EXPECTF--
Start
GearmanJob::workload (OO): normal
GearmanJob::workloadSize (OO): 6
Done
tests/gearman_002.phpt000064400000000425150414423330010576 0ustar00--TEST--
gearman_worker_set_id()
--SKIPIF--
<?php if (!extension_loaded("gearman")) print "skip"; ?>
--FILE--
<?php 

$worker= new GearmanWorker();
$worker->setId('test');

$worker = gearman_worker_create();
gearman_worker_set_id($worker, 'test');

echo "OK";
?>
--EXPECT--
OK
tests/gearman_client_012.phpt000064400000002065150414423330012137 0ustar00--TEST--
GearmanClient::addServer(), gearman_client_add_server()
--SKIPIF--
<?php if (!extension_loaded("gearman")) print "skip";
require_once('skipifconnect.inc');
?>
--FILE--
<?php 

$client = new GearmanClient();
print "GearmanClient::addServer(OO), implicit port: " . ($client->addServer('localhost') ? 'Success' : 'Failure') . PHP_EOL;
print "GearmanClient::addServer(OO), explicit port: " . ($client->addServer('localhost', 4730) ? 'Success' : 'Failure') . PHP_EOL;

$client2 = gearman_client_create();
print "gearman_client_add_server (Procedural), implicit port: " . (gearman_client_add_server($client2, 'localhost') ? 'Success' : 'Failure') . PHP_EOL;
print "gearman_client_add_server (Procedural): explicit port" . (gearman_client_add_server($client2, 'localhost', 4730) ? 'Success' : 'Failure') . PHP_EOL;

print "OK";
?>
--EXPECT--
GearmanClient::addServer(OO), implicit port: Success
GearmanClient::addServer(OO), explicit port: Success
gearman_client_add_server (Procedural), implicit port: Success
gearman_client_add_server (Procedural): explicit portSuccess
OK
tests/gearman_worker_integration_test_001.phpt000064400000004217150414423330015633 0ustar00--TEST--
Test Gearman worker methods
--SKIPIF--
<?php
require_once('skipif.inc');
require_once('skipifconnect.inc');
?>
--FILE--
<?php
require_once('connect.inc');

print "Start" . PHP_EOL;
$job_name = uniqid();
$pid = pcntl_fork();
if ($pid == -1) {
    die("Could not fork");
} else if ($pid > 0) {
    // Parent. This is the worker
    $worker = new GearmanWorker();
    print "addServer: " . var_export($worker->addServer($host, $port), true) . PHP_EOL;
    print "setTimeout: " . var_export($worker->setTimeout(100), true) . PHP_EOL;
    print "register: " . var_export($worker->register($job_name, 5), true) . PHP_EOL;
    print "register: " . var_export($worker->register($job_name . "1", 5), true) . PHP_EOL;
    print "register: " . var_export($worker->register($job_name . "2", 5), true) . PHP_EOL;
    print "register: " . var_export($worker->register($job_name . "3", 5), true) . PHP_EOL;
    print "addFunction: " . var_export(
        $worker->addFunction(
            $job_name,
            function($job) {
                print "workload: " . var_export($job->workload(), true) . PHP_EOL;
            }
        ), true
    ) . PHP_EOL;
    print "work: " . var_export($worker->work(), true) . PHP_EOL;
    print "unregister: " . var_export($worker->unregister($job_name), true) . PHP_EOL;
    print "unregisterAll: " . var_export($worker->unregisterAll(), true) . PHP_EOL;

    // Wait for child
    $exit_status = 0;
    if (pcntl_wait($exit_status) <= 0) {
        print "pcntl_wait exited with error" . PHP_EOL;
    } else if (!pcntl_wifexited($exit_status)) {
        print "child exited with error" . PHP_EOL;
    }
} else {
    //Child. This is the client. Don't echo anything here
    $client = new GearmanClient();
    if ($client->addServer($host, $port) !== true) {
        exit(1); // error
    };
    $client->doBackground($job_name, "nothing");
    if ($client->returnCode() != GEARMAN_SUCCESS) {
        exit(2); // error
    }
    exit(0);
}

print "Done";
--EXPECTF--
Start
addServer: true
setTimeout: true
register: true
register: true
register: true
register: true
addFunction: true
workload: 'nothing'
work: true
unregister: true
unregisterAll: true
Done
tests/gearman_task_003.phpt000064400000002136150414423330011622 0ustar00--TEST--
GearmanTask::jobHandle(), gearman_task_job_handle()
--SKIPIF--
<?php if (!extension_loaded("gearman")) print "skip";
require_once('skipifconnect.inc');
?>
--FILE--
<?php 

$client = new GearmanClient();
$client->addServer('localhost', 4730);
$client->setCreatedCallback(function ($task) {
	print "GearmanTask::jobHandle (OO): "
		. (preg_match('/^(.*):(.*):(.*)$/', $task->jobHandle())
			? 'String matches' : 'String does not match')
		. PHP_EOL;
});

$client->addTaskBackground("GearmanTaskFunction", "normal");
$client->runTasks();


$client2 = gearman_client_create();
gearman_client_add_server($client2, 'localhost', 4730);
gearman_client_set_created_callback($client2, function ($task) {
	print "gearman_task_job_handle (Procedural): "
		. (preg_match('/^(.*):(.*):(.*)$/', $task->jobHandle())
			? 'String matches' : 'String does not match')
		. PHP_EOL;
});
gearman_client_add_task_background($client2, "GearmanTaskFunction2", "normal");
gearman_client_run_tasks($client2);

print "OK";
?>
--EXPECT--
GearmanTask::jobHandle (OO): String matches
gearman_task_job_handle (Procedural): String matches
OK
tests/connect.inc000064400000000150150414423330010025 0ustar00<?php

$host = getenv("GEARMAN_TEST_HOST") ?: "localhost";
$port = getenv("GEARMAN_TEST_PORT") ?: 4730;
tests/gearman_client_018.phpt000064400000004321150414423330012142 0ustar00--TEST--
GearmanClient::jobStatusByUniqueKey(), gearman_client_job_status_by_unique_key()
--SKIPIF--
<?php if (!extension_loaded("gearman")) print "skip";
require_once('skipifconnect.inc');
?>
--FILE--
<?php 

$job_name = uniqid();

$client = new GearmanClient();
$client->addServer('localhost', 4730);

$oo_key = $job_name . "_oo";
$client->doBackground($job_name . "_OO", "test_jobStatusByUniqueKey");
list($is_known, $is_running, $numerator, $denominator) =
	$client->jobStatusByUniqueKey($oo_key);

print "GearmanClient::doStatus() (OO): " . PHP_EOL
/*
Note: This is returning falso, while jobStatus returns true.
Looks to be across multiple versions of libgearman (1.0.2 and 1.1.2 checked)
	. "  is_known is true: " . ($is_known === true ? 'Success' : 'Failure') .
	PHP_EOL
*/
	. "  is_running is false: " . ($is_running=== false ? 'Success' : 'Failure') .
	PHP_EOL
	. "  Numerator is 0: " . ($numerator == 0 ? 'Success' : 'Failure') .
	PHP_EOL
	. "  Denominator is 0: " . ($denominator == 0 ? 'Success' : 'Failure') .
	PHP_EOL;

$client2 = gearman_client_create();
gearman_client_add_server($client2, 'localhost', 4730);

$procedural_key = $job_name . "_procedural";
$job_handle = gearman_client_do_background($client2, $job_name .
	"_procedural", "test_jobStatusByUniqueKey");
list($is_known, $is_running, $numerator, $denominator) =
	gearman_client_job_status_by_unique_key($client2, $procedural_key);

print "gearman_client_job_status_by_unique_key() (Procedural): " . PHP_EOL
/*
Note: This is returning falso, while jobStatus returns true.
Looks to be across multiple versions of libgearman (1.0.2 and 1.1.2 checked)
	. "  is_known is true: " . ($is_known === true ? 'Success' : 'Failure') .
	PHP_EOL
*/
	. "  is_running is false: " . ($is_running === false ? 'Success' : 'Failure') .
	PHP_EOL
	. "  Numerator is 0: " . ($numerator == 0 ? 'Success' : 'Failure') .
	PHP_EOL
	. "  Denominator is 0: " . ($denominator == 0 ? 'Success' : 'Failure') .
	PHP_EOL;

print "OK";
?>
--EXPECT--
GearmanClient::doStatus() (OO): 
  is_running is false: Success
  Numerator is 0: Success
  Denominator is 0: Success
gearman_client_job_status_by_unique_key() (Procedural): 
  is_running is false: Success
  Numerator is 0: Success
  Denominator is 0: Success
OK
tests/gearman_client_014.phpt000064400000001172150414423330012137 0ustar00--TEST--
GearmanClient::wait(), gearman_client_wait()
--SKIPIF--
<?php if (!extension_loaded("gearman")) print "skip";
require_once('skipifconnect.inc');
?>
--FILE--
<?php 

$client = new GearmanClient();
$client->addServer('localhost', 4730);
print "Placeholder for GearmanClient::wait function" . PHP_EOL;
/*
print "GearmanClient::wait (OO): " . ($client->wait() ? 'Success' : 'Failure') . PHP_EOL;
*/

$client2 = gearman_client_create();
/*
print "gearman_client_wait (Procedural): " . (gearman_client_wait($client2) ? 'Success' : 'Failure') . PHP_EOL;
*/

print "OK";
?>
--EXPECT--
Placeholder for GearmanClient::wait function
OK
tests/gearman_client_002.phpt000064400000000767150414423330012145 0ustar00--TEST--
GearmanClient::returnCode(), gearman_client_return_code()
--SKIPIF--
<?php if (!extension_loaded("gearman")) print "skip"; ?>
--FILE--
<?php 

$client = new GearmanClient();
print "GearmanClient::returnCode (OO): " . $client->returnCode() . PHP_EOL;

$client2 = gearman_client_create();
print "gearman_client_return_code (Procedural): " . gearman_client_return_code($client2) . PHP_EOL;

print "OK";
?>
--EXPECT--
GearmanClient::returnCode (OO): 0
gearman_client_return_code (Procedural): 0
OK
tests/gearman_worker_002.phpt000064400000000732150414423330012170 0ustar00--TEST--
gearman_worker_return_code()
--SKIPIF--
<?php if (!extension_loaded("gearman")) print "skip"; ?>
--FILE--
<?php 

$worker = new GearmanWorker();
print "GearmanWorker::returnCode (OO): " . $worker->returnCode() . PHP_EOL;

$worker2 = gearman_worker_create();
print "gearman_worker_return_code (Procedural): " . gearman_worker_return_code($worker2) . PHP_EOL;

print "OK";
?>
--EXPECT--
GearmanWorker::returnCode (OO): 0
gearman_worker_return_code (Procedural): 0
OK
tests/gearman_worker_009.phpt000064400000001043150414423330012173 0ustar00--TEST--
gearman_worker_set_id()
--SKIPIF--
<?php if (!extension_loaded("gearman")) print "skip"; ?>
--FILE--
<?php 

$id = 'test';

$worker = new GearmanWorker();
print "GearmanWorker::setId() (OO): " . ($worker->setId($id) === true ? "Success" : "Failure").PHP_EOL;

$worker2 = gearman_worker_create();
print "gearman_worker_set_id() (Procedural): " . (gearman_worker_set_id($worker, $id) === true ? "Success" : "Failure").PHP_EOL;

print "OK";
?>
--EXPECT--
GearmanWorker::setId() (OO): Success
gearman_worker_set_id() (Procedural): Success
OK
tests/gearman_job_001.phpt000064400000000411150414423330011422 0ustar00--TEST--
new GearmanJob()
--SKIPIF--
<?php if (!extension_loaded("gearman")) print "skip"; ?>
--FILE--
<?php 

$job = new GearmanJob();
print "GearmanJob() (OO) class: " . get_class($job) . PHP_EOL;

print "OK";
?>
--EXPECT--
GearmanJob() (OO) class: GearmanJob
OK
tests/gearman_job_integration_test_006.phpt000064400000002611150414423330015075 0ustar00--TEST--
Test GearmanJob::sendFail()
--SKIPIF--
<?php
require_once('skipif.inc');
require_once('skipifconnect.inc');
?>
--FILE--
<?php
require_once('connect.inc');

print "Start" . PHP_EOL;

$job_name = uniqid();

$pid = pcntl_fork();
if ($pid == -1) {
    die("Could not fork");
} else if ($pid > 0) {
    // Parent. This is the worker
    $worker = new GearmanWorker();
    $worker->addServer($host, $port);
    $worker->addFunction(
        $job_name,
        function($job, $data) {
            print "GearmanJob::sendFail (OO): "
                . ($job->sendFail() === true ? 'Success' : 'Failure')
                . PHP_EOL;
            }
    );

    $worker->work();

    $worker->unregister($job_name);

    // Wait for child
    $exit_status = 0;
    if (pcntl_wait($exit_status) <= 0) {
        print "pcntl_wait exited with error" . PHP_EOL;
    } else if (!pcntl_wifexited($exit_status)) {
        print "child exited with error" . PHP_EOL;
    }
} else {
    //Child. This is the client. Don't echo anything here
    $client = new GearmanClient();
    if ($client->addServer($host, $port) !== true) {
        exit(1); // error
    };

    $tasks = [];
    $tasks[] = $client->addTask($job_name, "normal");
    $client->runTasks();
    if ($client->returnCode() != GEARMAN_SUCCESS) {
        exit(2); // error
    }
    exit(0);
}

print "Done";
--EXPECTF--
Start
GearmanJob::sendFail (OO): Success
Done
tests/gearman_job_integration_test_001.phpt000064400000002631150414423340015073 0ustar00--TEST--
Test GearmanJob::sendData()
--SKIPIF--
<?php
require_once('skipif.inc');
require_once('skipifconnect.inc');
?>
--FILE--
<?php
require_once('connect.inc');

print "Start" . PHP_EOL;

$job_name = uniqid();

$pid = pcntl_fork();
if ($pid == -1) {
    die("Could not fork");
} else if ($pid > 0) {
    // Parent. This is the worker
    $worker = new GearmanWorker();
    $worker->addServer($host, $port);
    $worker->addFunction(
        $job_name,
        function($job, $data) {
            print "GearmanJob::sendData (OO): "
                . ($job->sendData("{'foo': 'bar'}") === true ? 'Success' : 'Failure')
                . PHP_EOL;
            }
    );

    $worker->work();

    $worker->unregister($job_name);

    // Wait for child
    $exit_status = 0;
    if (pcntl_wait($exit_status) <= 0) {
        print "pcntl_wait exited with error" . PHP_EOL;
    } else if (!pcntl_wifexited($exit_status)) {
        print "child exited with error" . PHP_EOL;
    }
} else {
    //Child. This is the client. Don't echo anything here
    $client = new GearmanClient();
    if ($client->addServer($host, $port) !== true) {
        exit(1); // error
    };

    $tasks = [];
    $tasks[] = $client->addTask($job_name, "normal");
    $client->runTasks();
    if ($client->returnCode() != GEARMAN_SUCCESS) {
        exit(2); // error
    }
    exit(0);
}

print "Done";
--EXPECTF--
Start
GearmanJob::sendData (OO): Success
Done
tests/gearman_worker_007.phpt000064400000001520150414423340012172 0ustar00--TEST--
gearman_worker_add_options()
--SKIPIF--
<?php if (!extension_loaded("gearman")) print "skip"; ?>
--FILE--
<?php 

$worker = new GearmanWorker();
print "GearmanWorker::addOptions() (OO): " . ($worker->addOptions(GEARMAN_WORKER_NON_BLOCKING) === true ? 'Success' : 'Failure') . PHP_EOL;
print "GearmanWorker::options() (OO): " . $worker->options() . PHP_EOL;

$worker2 = gearman_worker_create();
print "gearman_worker_add_options() (Procedural): " . (gearman_worker_add_options($worker2, GEARMAN_WORKER_NON_BLOCKING) === true ? 'Success' : 'Failure') . PHP_EOL;
print "gearman_worker_options() (OO): " . gearman_worker_options($worker2) . PHP_EOL;

print "OK";
?>
--EXPECT--
GearmanWorker::addOptions() (OO): Success
GearmanWorker::options() (OO): 646
gearman_worker_add_options() (Procedural): Success
gearman_worker_options() (OO): 646
OK
tests/gearman_job_integration_test_005.phpt000064400000002672150414423340015104 0ustar00--TEST--
Test GearmanJob::sendException()
--SKIPIF--
<?php
require_once('skipif.inc');
require_once('skipifconnect.inc');
?>
--FILE--
<?php
require_once('connect.inc');

print "Start" . PHP_EOL;

$job_name = uniqid();

$pid = pcntl_fork();
if ($pid == -1) {
    die("Could not fork");
} else if ($pid > 0) {
    // Parent. This is the worker
    $worker = new GearmanWorker();
    $worker->addServer($host, $port);
    $worker->addFunction(
        $job_name,
        function($job, $data) {
            print "GearmanJob::sendException (OO): "
                . ($job->sendException("Sending exception from job.") === true ? 'Success' : 'Failure')
                . PHP_EOL;
            }
    );

    $worker->work();

    $worker->unregister($job_name);

    // Wait for child
    $exit_status = 0;
    if (pcntl_wait($exit_status) <= 0) {
        print "pcntl_wait exited with error" . PHP_EOL;
    } else if (!pcntl_wifexited($exit_status)) {
        print "child exited with error" . PHP_EOL;
    }
} else {
    //Child. This is the client. Don't echo anything here
    $client = new GearmanClient();
    if ($client->addServer($host, $port) !== true) {
        exit(1); // error
    };

    $tasks = [];
    $tasks[] = $client->addTask($job_name, "normal");
    $client->runTasks();
    if ($client->returnCode() != GEARMAN_SUCCESS) {
        exit(2); // error
    }
    exit(0);
}

print "Done";
--EXPECTF--
Start
GearmanJob::sendException (OO): Success
Done
tests/gearman_client_015.phpt000064400000001641150414423340012142 0ustar00--TEST--
GearmanClient::doJobHandle(), gearman_client_do_job_handle()
--SKIPIF--
<?php if (!extension_loaded("gearman")) print "skip";
require_once('skipifconnect.inc');
?>
--FILE--
<?php 

$client = new GearmanClient();
$client->addServer('localhost', 4730);

$job_handle = $client->doBackground("test_doJobHandle", "test_doJobHandle");
print "GearmanClient::doJobHandle() (OO): "
	. ($job_handle == $client->doJobHandle() ? 'Success' : 'Failure') . PHP_EOL;



$client2 = gearman_client_create();
gearman_client_add_server($client2, 'localhost', 4730);

$job_handle = gearman_client_do_background($client2, "test_do_job_handle", "test_do_job_handle");

print "gearman_client_do_job_handle() (Procedural): "
	. ($job_handle == gearman_client_do_job_handle($client2) ? 'Success' : 'Failure') . PHP_EOL;

print "OK";
?>
--EXPECT--
GearmanClient::doJobHandle() (OO): Success
gearman_client_do_job_handle() (Procedural): Success
OK
tests/gearman_worker_001.phpt000064400000000732150414423340012170 0ustar00--TEST--
gearman_worker_return_code()
--SKIPIF--
<?php if (!extension_loaded("gearman")) print "skip"; ?>
--FILE--
<?php 

$worker = new GearmanWorker();
print "GearmanWorker::returnCode (OO): " . $worker->returnCode() . PHP_EOL;

$worker2 = gearman_worker_create();
print "gearman_worker_return_code (Procedural): " . gearman_worker_return_code($worker2) . PHP_EOL;

print "OK";
?>
--EXPECT--
GearmanWorker::returnCode (OO): 0
gearman_worker_return_code (Procedural): 0
OK
tests/gearman_client_011.phpt000064400000001675150414423340012145 0ustar00--TEST--
GearmanClient::context(), GearmanClient::setContext(), gearman_client_context(), gearman_client_set_context()
--SKIPIF--
<?php if (!extension_loaded("gearman")) print "skip"; ?>
--FILE--
<?php 

$client = new GearmanClient();
print "GearmanClient::setContext(OO): " . ($client->setContext('context1_context1_context1_context1') ? 'Success' : 'Failure') . PHP_EOL;
print "GearmanClient::context (OO): " . $client->context() . PHP_EOL;

$client2 = gearman_client_create();
print "gearman_client_set_context (Procedural): " . (gearman_client_set_context($client2, 'context2_context2') ? 'Success' : 'Failure') . PHP_EOL;
print "gearman_client_context (Procedural): " . gearman_client_context($client2) . PHP_EOL;

print "OK";
?>
--EXPECT--
GearmanClient::setContext(OO): Success
GearmanClient::context (OO): context1_context1_context1_context1
gearman_client_set_context (Procedural): Success
gearman_client_context (Procedural): context2_context2
OK
tests/gearman_task_005.phpt000064400000002466150414423340011633 0ustar00--TEST--
GearmanTask::data(), gearman_task_data(),
GearmanTask::dataSize(), gearman_task_data_size()
--SKIPIF--
<?php if (!extension_loaded("gearman")) print "skip";
require_once('skipifconnect.inc');
?>
--FILE--
<?php 

$client = new GearmanClient();
$client->addServer('localhost', 4730);
$client->setCreatedCallback(function ($task) {
	print "GearmanTask::data (OO): "
		. ($task->data() === '' ? 'Success' : 'Failure') . PHP_EOL;
	print "GearmanTask::dataSize (OO): "
		. ($task->dataSize() == 0 ? 'Success' : 'Failure') . PHP_EOL;
});

$client->addTaskBackground("GearmanTaskFunction", "normal", "OO data");
$client->runTasks();


$client2 = gearman_client_create();
gearman_client_add_server($client2, 'localhost', 4730);
gearman_client_set_created_callback($client2, function ($task) {
	print "gearman_task_data (Procedural): "
		. (gearman_task_data($task) === '' ? 'Success' : 'Failure') . PHP_EOL;
	print "gearman_task_data_size (Procedural): "
		. (gearman_task_data_size($task) == 0 ? 'Success' : 'Failure') . PHP_EOL;
});
gearman_client_add_task_background($client2, "GearmanTaskFunction2", "normal");
gearman_client_run_tasks($client2);

print "OK";
?>
--EXPECT--
GearmanTask::data (OO): Success
GearmanTask::dataSize (OO): Success
gearman_task_data (Procedural): Success
gearman_task_data_size (Procedural): Success
OK
tests/gearman_job_002.phpt000064400000002522150414423340011431 0ustar00--TEST--
GearmanJob::returnCode(), gearman_job_return_code(),
GearmanJob::setReturn(), gearman_job_set_return()
--SKIPIF--
<?php if (!extension_loaded("gearman")) print "skip"; ?>
--FILE--
<?php 

$job = new GearmanJob();
print "GearmanJob::returnCode (OO): " . $job->returnCode() . PHP_EOL;
print "GearmanJob::setReturn with value GEARMAN_TIMEOUT (OO): "
	. ($job->setReturn(GEARMAN_TIMEOUT) ? 'Success' : 'Failure')
	. PHP_EOL;
print "GearmanJob::returnCode matches GEARMAN_TIMEOUT (OO): "
	. ($job->returnCode() == GEARMAN_TIMEOUT ? 'Success' : 'Failure') . PHP_EOL;


$job2 = new GearmanJob();
print "gearman_job_return_code (Procedural): " . gearman_job_return_code($job2) . PHP_EOL;
print "gearman_job_set_return with value GEARMAN_TIMEOUT (Procedural): "
	. (gearman_job_set_return($job2, GEARMAN_TIMEOUT) ? 'Success' : 'Failure')
	. PHP_EOL;
print "gearman_job_return_code matches GEARMAN_TIMEOUT (OO): "
	. (gearman_job_return_code($job2) == GEARMAN_TIMEOUT ? 'Success' : 'Failure') . PHP_EOL;

print "OK";
?>
--EXPECT--
GearmanJob::returnCode (OO): 0
GearmanJob::setReturn with value GEARMAN_TIMEOUT (OO): Success
GearmanJob::returnCode matches GEARMAN_TIMEOUT (OO): Success
gearman_job_return_code (Procedural): 0
gearman_job_set_return with value GEARMAN_TIMEOUT (Procedural): Success
gearman_job_return_code matches GEARMAN_TIMEOUT (OO): Success
OK
tests/gearman_client_005.phpt000064400000001040150414423340012132 0ustar00--TEST--
GearmanClient::options(), gearman_client_options()
--SKIPIF--
<?php if (!extension_loaded("gearman")) print "skip"; ?>
--FILE--
<?php 

$client = new GearmanClient();
$client->setOptions(32);
print "GearmanClient::options (OO): " . $client->options() . PHP_EOL;

$client2 = gearman_client_create();
gearman_client_set_options($client2, 32);
print "gearman_client_options (Procedural): " . gearman_client_options($client2) . PHP_EOL;

print "OK";
?>
--EXPECT--
GearmanClient::options (OO): 32
gearman_client_options (Procedural): 32
OK
tests/gearman_client_004.phpt000064400000000747150414423340012146 0ustar00--TEST--
GearmanClient::getErrno(), gearman_client_get_errno()
--SKIPIF--
<?php if (!extension_loaded("gearman")) print "skip"; ?>
--FILE--
<?php 

$client = new GearmanClient();
print "GearmanClient::getErrno (OO): " . $client->getErrno() . PHP_EOL;

$client2 = gearman_client_create();
print "gearman_client_get_errno (Procedural): " . gearman_client_get_errno($client2) . PHP_EOL;

print "OK";
?>
--EXPECT--
GearmanClient::getErrno (OO): 0
gearman_client_get_errno (Procedural): 0
OK
tests/gearman_task_002.phpt000064400000001643150414423350011625 0ustar00--TEST--
GearmanTask::unique, gearman_task_unique
--SKIPIF--
<?php if (!extension_loaded("gearman")) print "skip";
require_once('skipifconnect.inc');
?>
--FILE--
<?php 

$client = new GearmanClient();
$client->addServer('localhost', 4730);
$task = $client->addTask("GearmanTaskFunction", "normal");
print "GearmanTask::unique (OO): "
	. (preg_match('/^(.*)-(.*)-(.*)-(.*)-(.*)$/', $task->unique())
		? 'String matches' : 'String does not match')
	. PHP_EOL;

$client2 = gearman_client_create();
gearman_client_add_server($client2, 'localhost', 4730);
$task2 = gearman_client_add_task($client2, "GearmanTaskFunction2", "normal");
print "gearman_client_unique (Procedural): "
	. (preg_match('/^(.*)-(.*)-(.*)-(.*)-(.*)$/', gearman_task_unique($task))
		? 'String matches' : 'String does not match')
	. PHP_EOL;

print "OK";
?>
--EXPECT--
GearmanTask::unique (OO): String matches
gearman_client_unique (Procedural): String matches
OK
tests/gearman_worker_003.phpt000064400000000663150414423350012176 0ustar00--TEST--
gearman_worker_error()
--SKIPIF--
<?php if (!extension_loaded("gearman")) print "skip"; ?>
--FILE--
<?php 

$worker = new GearmanWorker();
print "GearmanWorker::error (OO): '" . $worker->error() . "'\n";

$worker2 = gearman_worker_create();
print "gearman_worker_error (Procedural): '" . gearman_worker_error($worker2) . "'\n";

print "OK";
?>
--EXPECT--
GearmanWorker::error (OO): ''
gearman_worker_error (Procedural): ''
OK
tests/gearman_worker_015.phpt000064400000001300150414423350012166 0ustar00--TEST--
gearman_worker_ping()
--SKIPIF--
<?php if (!extension_loaded("gearman")) print "skip";
require_once('skipifconnect.inc');
?>
--FILE--
<?php 

$host = 'localhost';
$port = 4730;

$json_workload = '{"workload":"test"}';

$worker = new GearmanWorker();
$worker->addServer($host, $port);
echo "GearmanWorker::server() (OO): ".($worker->ping($json_workload) ? "Success" : "Failure").PHP_EOL;

$worker2 = gearman_worker_create();
gearman_worker_add_server($worker, $host, $port);
echo "gearman_worker_work() (Procedural): ".($worker->ping($json_workload) ? "Success" : "Failure").PHP_EOL;

print "OK";
?>
--EXPECT--
GearmanWorker::server() (OO): Success
gearman_worker_work() (Procedural): Success
OK
tests/skipif.inc000064400000000256150414423350007672 0ustar00<?php

if (!extension_loaded("gearman")) {
    die("skip gearman extension unavailable");
}

if (!extension_loaded("pcntl")) {
    die("skip pcntl extension unavailable");
}
tests/gearman_worker_008.phpt000064400000002314150414423350012176 0ustar00--TEST--
gearman_worker_timeout(), gearman_worker_set_timeout()
--SKIPIF--
<?php if (!extension_loaded("gearman")) print "skip"; ?>
--FILE--
<?php 

$timeout = 5;

$worker = new GearmanWorker();
print "GearmanWorker::timeout() (OO, before setting): " . $worker->timeout() . PHP_EOL;
print "GearmanWorker::setTimeout() (OO): " .($worker->setTimeout($timeout) === true ? "Success" : "Failure") . PHP_EOL;
print "GearmanWorker::timeout() (OO, after setting): " . $worker->timeout() . PHP_EOL;

$worker2 = gearman_worker_create();
print "gearman_worker_timeout() (Procedural, before setting): " . gearman_worker_timeout($worker2) . PHP_EOL;
print "gearman_worker_set_timeout() (Procedural): " . (gearman_worker_set_timeout($worker2, $timeout) === true ? "Success" : "Failure") . PHP_EOL;
print "gearman_worker_timeout() (Procedural, after setting): " . gearman_worker_timeout($worker2) . PHP_EOL;

print "OK";
?>
--EXPECT--
GearmanWorker::timeout() (OO, before setting): -1
GearmanWorker::setTimeout() (OO): Success
GearmanWorker::timeout() (OO, after setting): 5
gearman_worker_timeout() (Procedural, before setting): -1
gearman_worker_set_timeout() (Procedural): Success
gearman_worker_timeout() (Procedural, after setting): 5
OK
tests/gearman_client_003.phpt000064400000000713150414423350012137 0ustar00--TEST--
GearmanClient::error(), gearman_client_error()
--SKIPIF--
<?php if (!extension_loaded("gearman")) print "skip"; ?>
--FILE--
<?php 

$client = new GearmanClient();
print "GearmanClient::error (OO): '" . $client->error() . "'\n";

$client2 = gearman_client_create();
print "gearman_client_error (Procedural): '" . gearman_client_error($client2) . "'\n";

print "OK";
?>
--EXPECT--
GearmanClient::error (OO): ''
gearman_client_error (Procedural): ''
OK
tests/gearman_client_009.phpt000064400000000735150414423350012151 0ustar00--TEST--
GearmanClient::timeout(), gearman_client_timeout()
--SKIPIF--
<?php if (!extension_loaded("gearman")) print "skip"; ?>
--FILE--
<?php 

$client = new GearmanClient();
print "GearmanClient::timeout (OO): " . $client->timeout() . PHP_EOL;

$client2 = gearman_client_create();
print "gearman_client_timeout (Procedural): " . gearman_client_timeout($client2) . PHP_EOL;

print "OK";
?>
--EXPECT--
GearmanClient::timeout (OO): -1
gearman_client_timeout (Procedural): -1
OK
tests/gearman_worker_006.phpt000064400000001522150414423350012174 0ustar00--TEST--
gearman_worker_set_options()
--SKIPIF--
<?php if (!extension_loaded("gearman")) print "skip"; ?>
--FILE--
<?php 

$worker = new GearmanWorker();
print "GearmanWorker::setOptions (OO): " . ($worker->setOptions(GEARMAN_WORKER_NON_BLOCKING) === true ? 'Success' : 'Failure') . PHP_EOL;
print "GearmanWorker::options() (OO): " . $worker->options() . PHP_EOL;

$worker2 = gearman_worker_create();
print "gearman_worker_set_options (Procedural): " . (gearman_worker_set_options($worker, GEARMAN_WORKER_NON_BLOCKING) === true ? 'Success' : 'Failure') . PHP_EOL;
print "gearman_worker_options() (Procedural): " . gearman_worker_options($worker) . PHP_EOL;

print "OK";
?>
--EXPECT--
GearmanWorker::setOptions (OO): Success
GearmanWorker::options() (OO): 6
gearman_worker_set_options (Procedural): Success
gearman_worker_options() (Procedural): 6
OK
tests/gearman_job_integration_test_009.phpt000064400000002643150414423350015107 0ustar00--TEST--
Test GearmanJob::unique()
--SKIPIF--
<?php
require_once('skipif.inc');
require_once('skipifconnect.inc');
?>
--FILE--
<?php
require_once('connect.inc');

print "Start" . PHP_EOL;

$job_name = uniqid();

$pid = pcntl_fork();
if ($pid == -1) {
    die("Could not fork");
} else if ($pid > 0) {
    // Parent. This is the worker
    $worker = new GearmanWorker();
    $worker->addServer($host, $port);
    $worker->addFunction(
        $job_name,
        function($job, $data) {
            print "GearmanJob::unique (OO): "
                . (preg_match('/^(.*)-(.*)-(.*)-(.*)-(.*)$/',$job->unique()) ? 'Success' : 'Failure')
                . PHP_EOL;
            }
    );

    $worker->work();

    $worker->unregister($job_name);

    // Wait for child
    $exit_status = 0;
    if (pcntl_wait($exit_status) <= 0) {
        print "pcntl_wait exited with error" . PHP_EOL;
    } else if (!pcntl_wifexited($exit_status)) {
        print "child exited with error" . PHP_EOL;
    }
} else {
    //Child. This is the client. Don't echo anything here
    $client = new GearmanClient();
    if ($client->addServer($host, $port) !== true) {
        exit(1); // error
    };

    $tasks = [];
    $tasks[] = $client->addTask($job_name, "normal");
    $client->runTasks();
    if ($client->returnCode() != GEARMAN_SUCCESS) {
        exit(2); // error
    }
    exit(0);
}

print "Done";
--EXPECTF--
Start
GearmanJob::unique (OO): Success
Done
tests/gearman_001.phpt000064400000000315150414423350010575 0ustar00--TEST--
Check for gearman  presence
--SKIPIF--
<?php if (!extension_loaded("gearman")) print "skip"; ?>
--FILE--
<?php 
echo "gearman extension is available";
?>
--EXPECT--
gearman extension is available
tests/gearman_client_020.phpt000064400000004342150414423360012141 0ustar00--TEST--
GearmanClient::clearCallbacks(), gearman_client_clear_callbacks()
--SKIPIF--
<?php if (!extension_loaded("gearman")) print "skip";
require_once('skipifconnect.inc');
?>
--FILE--
<?php 

$client = new GearmanClient();
$client->addServer('localhost', 4730);
print "GearmanClient::clearCallbacks (OO) (No callbacks set): " . ($client->clearCallbacks() ? 'Success' : 'Failure') . PHP_EOL;
$client->setWorkloadCallback(function($task, $context){});
$client->setCreatedCallback(function($task, $context){});
$client->setDataCallback(function($task, $context){});
$client->setWarningCallback(function($task, $context){});
$client->setStatusCallback(function($task, $context){});
$client->setCompleteCallback(function($task, $context){});
$client->setExceptionCallback(function($task, $context){});
$client->setFailCallback(function($task, $context){});
print "GearmanClient::clearCallbacks (OO) (Callbacks set): " . ($client->clearCallbacks() ? 'Success' : 'Failure') . PHP_EOL;

$client2 = gearman_client_create();
gearman_client_add_server($client2, 'localhost', 4730);
print "gearman_client_clear_callbacks (Procedural) (No callbacks set: "
	. (gearman_client_clear_callbacks($client2) ? 'Success' : 'Failure') . PHP_EOL;
gearman_client_set_workload_callback($client2, function($task, $context){});
gearman_client_set_created_callback($client2, function($task, $context){});
gearman_client_set_data_callback($client2, function($task, $context){});
gearman_client_set_warning_callback($client2, function($task, $context){});
gearman_client_set_status_callback($client2, function($task, $context){});
gearman_client_set_complete_callback($client2, function($task, $context){});
gearman_client_set_exception_callback($client2, function($task, $context){});
gearman_client_set_fail_callback($client2, function($task, $context){});
print "gearman_client_clear_callbacks (Procedural) (Callbacks set: "
	. (gearman_client_clear_callbacks($client2) ? 'Success' : 'Failure') . PHP_EOL;

print "OK";
?>
--EXPECT--
GearmanClient::clearCallbacks (OO) (No callbacks set): Success
GearmanClient::clearCallbacks (OO) (Callbacks set): Success
gearman_client_clear_callbacks (Procedural) (No callbacks set: Success
gearman_client_clear_callbacks (Procedural) (Callbacks set: Success
OK
tests/gearman_job_integration_test_003.phpt000064400000002622150414423360015077 0ustar00--TEST--
Test GearmanJob::sendStatus
--SKIPIF--
<?php
require_once('skipif.inc');
require_once('skipifconnect.inc');
?>
--FILE--
<?php
require_once('connect.inc');

print "Start" . PHP_EOL;

$job_name = uniqid();

$pid = pcntl_fork();
if ($pid == -1) {
    die("Could not fork");
} else if ($pid > 0) {
    // Parent. This is the worker
    $worker = new GearmanWorker();
    $worker->addServer($host, $port);
    $worker->addFunction(
        $job_name,
        function($job, $data) {
            print "GearmanJob::sendStatus (OO): "
                . ($job->sendStatus(1,2) === true ? 'Success' : 'Failure')
                . PHP_EOL;
            }
    );

    $worker->work();

    $worker->unregister($job_name);

    // Wait for child
    $exit_status = 0;
    if (pcntl_wait($exit_status) <= 0) {
        print "pcntl_wait exited with error" . PHP_EOL;
    } else if (!pcntl_wifexited($exit_status)) {
        print "child exited with error" . PHP_EOL;
    }
} else {
    //Child. This is the client. Don't echo anything here
    $client = new GearmanClient();
    if ($client->addServer($host, $port) !== true) {
        exit(1); // error
    };

    $tasks = [];
    $tasks[] = $client->addTask($job_name, "normal");
    $client->runTasks();
    if ($client->returnCode() != GEARMAN_SUCCESS) {
        exit(2); // error
    }
    exit(0);
}

print "Done";
--EXPECTF--
Start
GearmanJob::sendStatus (OO): Success
Done
tests/gearman_client_006.phpt000064400000002204150414423360012140 0ustar00--TEST--
GearmanClient::setOptions(), gearman_client_set_options()
--SKIPIF--
<?php if (!extension_loaded("gearman")) print "skip"; ?>
--FILE--
<?php 

$client = new GearmanClient();
$client->setOptions(32);
print "GearmanClient::options (OO): " . $client->options() . PHP_EOL;
print "GearmanClient::setOptions (OO): " . ($client->setOptions(GEARMAN_CLIENT_NON_BLOCKING) ? 'Success' : 'Failure') . PHP_EOL;
print "GearmanClient::options (OO): " . $client->options() . PHP_EOL;

$client2 = gearman_client_create();
gearman_client_set_options($client2, 32);
print "gearman_client_options (Procedural): " . gearman_client_options($client2) . PHP_EOL;
print "gearman_client_set_options (Procedural): " . (gearman_client_set_options($client2, GEARMAN_CLIENT_NON_BLOCKING) ? 'Success' : 'Failure') . PHP_EOL;
print "gearman_client_options (Procedural): " . gearman_client_options($client2) . PHP_EOL;

print "OK";
?>
--EXPECT--
GearmanClient::options (OO): 32
GearmanClient::setOptions (OO): Success
GearmanClient::options (OO): 2
gearman_client_options (Procedural): 32
gearman_client_set_options (Procedural): Success
gearman_client_options (Procedural): 2
OK
tests/gearman_job_integration_test_008.phpt000064400000002664150414423360015112 0ustar00--TEST--
Test GearmanJob::functionName()
--SKIPIF--
<?php
require_once('skipif.inc');
require_once('skipifconnect.inc');
?>
--FILE--
<?php
require_once('connect.inc');

print "Start" . PHP_EOL;

$job_name = uniqid();

$pid = pcntl_fork();
if ($pid == -1) {
    die("Could not fork");
} else if ($pid > 0) {
    // Parent. This is the worker
    $worker = new GearmanWorker();
    $worker->addServer($host, $port);
    $worker->addFunction(
        $job_name,
        function($job, $data) {
	    global $job_name;
            print "GearmanJob::functionName (OO): "
                . ($job->functionName() == $job_name ? 'Success' : 'Failure')
                . PHP_EOL;
            }
    );

    $worker->work();

    $worker->unregister($job_name);

    // Wait for child
    $exit_status = 0;
    if (pcntl_wait($exit_status) <= 0) {
        print "pcntl_wait exited with error" . PHP_EOL;
    } else if (!pcntl_wifexited($exit_status)) {
        print "child exited with error" . PHP_EOL;
    }
} else {
    //Child. This is the client. Don't echo anything here
    $client = new GearmanClient();
    if ($client->addServer($host, $port) !== true) {
        exit(1); // error
    };

    $tasks = [];
    $tasks[] = $client->addTask($job_name, "normal");
    $client->runTasks();
    if ($client->returnCode() != GEARMAN_SUCCESS) {
        exit(2); // error
    }
    exit(0);
}

print "Done";
--EXPECTF--
Start
GearmanJob::functionName (OO): Success
Done
tests/gearman_worker_004.phpt000064400000000674150414423360012202 0ustar00--TEST--
gearman_worker_errno()
--SKIPIF--
<?php if (!extension_loaded("gearman")) print "skip"; ?>
--FILE--
<?php 

$worker = new GearmanWorker();
print "GearmanWorker::getErrno (OO): " . $worker->getErrno() . PHP_EOL;

$worker2 = gearman_worker_create();
print "gearman_worker_errno (Procedural): " . gearman_worker_errno($worker2) . PHP_EOL;

print "OK";
?>
--EXPECT--
GearmanWorker::getErrno (OO): 0
gearman_worker_errno (Procedural): 0
OK
tests/gearman_worker_010.phpt000064400000002023150414423360012165 0ustar00--TEST--
gearman_worker_add_server(), gearman_worker_add_servers()
--SKIPIF--
<?php if (!extension_loaded("gearman")) print "skip";
require_once('skipifconnect.inc');
?>
--FILE--
<?php 

$host = 'localhost';
$port = 4730;

$worker = new GearmanWorker();
print "GearmanWorker::addServer() (OO):" . ($worker->addServer($host, $port) === true ? "Success" : "Failure").PHP_EOL;
print "GearmanWorker::addServers() (OO): " . ($worker->addServers("$host:$port") === true ? "Success" : "Failure").PHP_EOL;

$worker2 = gearman_worker_create();
print "gearman_worker_add_server() (Procedural): " . (gearman_worker_add_server($worker, $host, $port) === true ? "Success" : "Failure").PHP_EOL;
print "gearman_worker_add_servers() (Procedural): " . (gearman_worker_add_servers($worker, "$host:$port") === true ? "Success" : "Failure").PHP_EOL;

print "OK";
?>
--EXPECT--
GearmanWorker::addServer() (OO):Success
GearmanWorker::addServers() (OO): Success
gearman_worker_add_server() (Procedural): Success
gearman_worker_add_servers() (Procedural): Success
OK
tests/gearman_worker_017.phpt000064400000000462150414423360012201 0ustar00--TEST--
unserialize(serialize(GearmanWorker))
--SKIPIF--
<?php if (!extension_loaded("gearman")) print "skip"; ?>
--FILE--
<?php

$i = 0;
while ($i <= 5) {
    echo $i;
    $client = new GearmanWorker();
    unserialize(serialize($client));
    $i++;
}
print PHP_EOL;

print "OK";
?>
--EXPECT--
012345
OK
tests/gearman_tasks_integration_test_001.phpt000064400000003705150414423360015453 0ustar00--TEST--
Test Gearman worker methods
--SKIPIF--
<?php
require_once('skipif.inc');
require_once('skipifconnect.inc');
?>
--FILE--
<?php
require_once('connect.inc');

print "Start" . PHP_EOL;

$job_name = uniqid();

$pid = pcntl_fork();
if ($pid == -1) {
    die("Could not fork");
} else if ($pid > 0) {
    // Parent. This is the worker
    $worker = new GearmanWorker();
    print "addServer: " . var_export($worker->addServer($host, $port), true) . PHP_EOL;
    print "addFunction: " . var_export(
        $worker->addFunction(
            $job_name,
            function($job) {
                print "workload: " . var_export($job->workload(), true) . PHP_EOL;
            }
        ),
        true
    ) . PHP_EOL;

    for ($i = 0; $i < 6; $i++) {
        $worker->work();
    }

    print "unregister: " . var_export($worker->unregister($job_name), true) . PHP_EOL;

    // Wait for child
    $exit_status = 0;
    if (pcntl_wait($exit_status) <= 0) {
        print "pcntl_wait exited with error" . PHP_EOL;
    } else if (!pcntl_wifexited($exit_status)) {
        print "child exited with error" . PHP_EOL;
    }
} else {
    //Child. This is the client. Don't echo anything here
    $client = new GearmanClient();
    if ($client->addServer($host, $port) !== true) {
        exit(1); // error
    };

    $tasks = [];
    $tasks[] = $client->addTask($job_name, "normal");
    $tasks[] = $client->addTaskBackground($job_name, "normalbg");
    $tasks[] = $client->addTaskHigh($job_name, 1);
    $tasks[] = $client->addTaskHighBackground($job_name, 2.0);
    $tasks[] = $client->addTaskLow($job_name, "low");
    $tasks[] = $client->addTaskLowBackground($job_name, true);
    $client->runTasks();
    if ($client->returnCode() != GEARMAN_SUCCESS) {
        exit(2); // error
    }
    exit(0);
}

print "Done";
--EXPECTF--
Start
addServer: true
addFunction: true
workload: '2'
workload: '1'
workload: 'normalbg'
workload: 'normal'
workload: '1'
workload: 'low'
unregister: true
Done
tests/gearman_client_001.phpt000064400000000754150414423360012143 0ustar00--TEST--
new GearmanClient(), gearman_client_create()
--SKIPIF--
<?php if (!extension_loaded("gearman")) print "skip"; ?>
--FILE--
<?php 

$client = new GearmanClient();
print "GearmanClient() (OO) class: " . get_class($client) . PHP_EOL;

$client2 = gearman_client_create();
print "gearman_client_create() (Procedural) class: " . get_class($client2) . PHP_EOL;

print "OK";
?>
--EXPECT--
GearmanClient() (OO) class: GearmanClient
gearman_client_create() (Procedural) class: GearmanClient
OK
tests/gearman_task_006.phpt000064400000000455150414423360011632 0ustar00--TEST--
unserialize(serialize(GearmanTask))
--SKIPIF--
<?php if (!extension_loaded("gearman")) print "skip"; ?>
--FILE--
<?php
$i = 0;
while ($i <= 5) {
    echo $i;
    $client = new GearmanTask();
    unserialize(serialize($client));
    $i++;
}
print PHP_EOL;

print "OK";
?>
--EXPECT--
012345
OK
tests/gearman_tasks_integration_test_002.phpt000064400000004471150414423360015455 0ustar00--TEST--
Test Gearman worker methods
--SKIPIF--
<?php
require_once('skipif.inc');
require_once('skipifconnect.inc');
require_once('skipifversion.inc');

?>
--FILE--
<?php
require_once('connect.inc');

print "Start" . PHP_EOL;

$job_name = uniqid();

$contexts = [
        "success",
	"fail",
	"exception"
    ];

$pid = pcntl_fork();
if ($pid == -1) {
    die("Could not fork");
} else if ($pid == 0) {
    // Child. This is the worker.
    // Don't echo anything here
    $worker = new GearmanWorker();
    $worker->addServer($host, $port);
    $worker->addFunction(
        $job_name,
        function($job) {
            if ($job->workload() == "success") {
                return "done";
            } else if ($job->workload() == "exception") {
                $job->sendException("unhandled");
                return "exception";
            } else if ($job->workload() == "fail") {
                $job->sendFail();
                return "fail";
            }
        }
    );

    for ($i = 0; $i < count($contexts); $i++) {
        $worker->work();
    }

    $worker->unregister($job_name);
    exit(0);
} else {
    //Parent. This is the client.
    $client = new GearmanClient();
    if ($client->addServer($host, $port) !== true) {
        exit(1); // error
    };

    $client->setCompleteCallback(function($task) {
        print "Complete: " . $task->data() . PHP_EOL;
    });
    $client->setDataCallback(function($task) {
        print "Data: " . $task->data() . PHP_EOL;
    });
    $client->setExceptionCallback(function($task) {
        print "Exception: " . $task->data() . PHP_EOL;
    });
    $client->setFailCallback(function($task) {
        print "Fail" . PHP_EOL;
    });

    $tasks = [];
    foreach ($contexts as $c) {
        $tasks[] = $client->addTask($job_name, $c);
    }
    $client->runTasks();
    print "returnCode: " . var_export($client->returnCode(), true) . PHP_EOL;
    print "clearCallbacks: " . var_export($client->clearCallbacks(), true) . PHP_EOL;

    // Wait for child
    $exit_status = 0;
    if (pcntl_wait($exit_status) <= 0) {
        print "pcntl_wait exited with error" . PHP_EOL;
    } else if (!pcntl_wifexited($exit_status)) {
        print "child exited with error" . PHP_EOL;
    }
}

print "Done";
--EXPECTF--
Start
Exception: unhandled
Fail
Complete: done
returnCode: 0
clearCallbacks: true
Done
tests/skipifconnect.inc000064400000000614150414423360011243 0ustar00<?php

if (getenv("SKIP_ONLINE_TESTS")) die("skip online test");

require_once('connect.inc');

$sock = @fsockopen($host, $port);
if ($sock === false) {
    die("skip unable to connect");
}

$command = "getpid\n";
if (fwrite($sock, $command) !== strlen($command)) {
    die("skip unable to write getpid");
}

if (fread($sock, 8) === false) {
    die("skip unable to read pid");
}

fclose($sock);
tests/gearman_client_021.phpt000064400000005073150414423360012144 0ustar00--TEST--
GearmanClient::enableExceptionHandler(),gearman_client_enable_exception_handler()
--SKIPIF--
<?php if (!extension_loaded("gearman")) print "skip";
require_once('skipifconnect.inc');
?>
--FILE--
<?php 

// Test 1: GearmanClient::addServers, Exception callback disabled. Exceptions
// should be skipped until we call enableExceptionHandler. Port 4731 is not
// being used as the port for GearmanD, so it will fail
$client = new GearmanClient();
$client->addServers('localhost:4731,localhost', false);

// Enabling the exception handler, which will attempt to connect to
// the server and in doing so throw an exception since we can't
// connect to a server that doesn't exist
try {
	$client->enableExceptionHandler();
} catch (Exception $e) {
	print "Exception 1 caught: " . $e->getMessage() . PHP_EOL;
}

// Test 2: GearmanClient::addServers,  Exception callback enabled (by default).
// Here, we don't give the second param, so the exception handler is enabled
// upon calling addServers instead of later in enableExceptionHandler
$client2 = new GearmanClient();

try {
	$client2->addServers('localhost:4731,localhost');
} catch (Exception $e) {
	print "Exception 2 caught: " . $e->getMessage() . PHP_EOL;
}

// Test 3: GearmanClient::addServers, Also, when we explicitly enable in addServers
$client3 = new GearmanClient();

try {
	$client3->addServers('localhost:4731,localhost', true);
} catch (Exception $e) {
	print "Exception 3 caught: " . $e->getMessage() . PHP_EOL;
}

// Now, do the same as above but with addServer (singular)
// Test 4: GearmanClient::addServer, Exception callback disabled
$client4 = new GearmanClient();
$client4->addServer('localhost', 4731, false);

try {
	$client4->enableExceptionHandler();
} catch (Exception $e) {
	print "Exception 4 caught: " . $e->getMessage() . PHP_EOL;
}

// Test 5: GearmanClient::addServer, default
$client5 = new GearmanClient();

try {
	$client5->addServer('localhost', 4731);
} catch (Exception $e) {
	print "Exception 5 caught: " . $e->getMessage() . PHP_EOL;
}

// Test 6: GearmanClient::addServer, explicitly set enableExceptionHandler
$client6 = new GearmanClient();

try {
	$client6->addServer('localhost', 4731, true);
} catch (Exception $e) {
	print "Exception 6 caught: " . $e->getMessage() . PHP_EOL;
}

print "OK";
?>
--EXPECTF--
Exception 1 caught: Failed to set exception option
Exception 2 caught: Failed to set exception option
Exception 3 caught: Failed to set exception option
Exception 4 caught: Failed to set exception option
Exception 5 caught: Failed to set exception option
Exception 6 caught: Failed to set exception option
OK
tests/gearman_client_019.phpt000064400000001241150414423360012144 0ustar00--TEST--
GearmanClient::ping(), gearman_client_ping()
--SKIPIF--
<?php if (!extension_loaded("gearman")) print "skip";
require_once('skipifconnect.inc');
?>
--FILE--
<?php 

$client = new GearmanClient();
$client->addServer('localhost', 4730);
print "GearmanClient::ping (OO): " . ($client->ping('oo data') ? 'Success' : 'Failure') . PHP_EOL;

$client2 = gearman_client_create();
gearman_client_add_server($client2, 'localhost', 4730);
print "gearman_client_ping (Procedural): "
	. (gearman_client_ping($client2,'procedural data') ? 'Success' : 'Failure') . PHP_EOL;

print "OK";
?>
--EXPECT--
GearmanClient::ping (OO): Success
gearman_client_ping (Procedural): Success
OK
tests/gearman_client_022.phpt000064400000000462150414423370012143 0ustar00--TEST--
unserialize(serialize(GearmanClient))
--SKIPIF--
<?php if (!extension_loaded("gearman")) print "skip"; ?>
--FILE--
<?php

$i = 0;
while ($i <= 5) {
    echo $i;
    $client = new GearmanClient();
    unserialize(serialize($client));
    $i++;
}
print PHP_EOL;

print "OK";
?>
--EXPECT--
012345
OK
tests/gearman_worker_014.phpt000064400000002510150414423370012173 0ustar00--TEST--
gearman_worker_work()
--SKIPIF--
<?php if (!extension_loaded("gearman")) print "skip"; 
require_once('skipifconnect.inc');
?>
--FILE--
<?php 

$host = 'localhost';
$port = 4730;
$job = 'GenericTestJob';
$func = 'do_work';
$workload = '{"workload":"test"}';

// Adding 2 jobs, one for OO and one for procedural
$client = new GearmanClient();
$client->addServer($host, $port);
$handle = $client->doBackground($job, $workload);
$client->doBackground($job, $workload);

print "GearmanWorker::doBackground() (OO): ".(preg_match('/^H:'.gethostname().':\d+$/', $handle) === 1? 'Success' : 'Failure').PHP_EOL;

$worker = new GearmanWorker();
$worker->addServer($host, $port);
$worker->addFunction($job, $func);

print "GearmanWorker::work() (OO): ".($worker->work() === true ? 'Success' : 'Failure') . PHP_EOL;

$worker2 = gearman_worker_create();
gearman_worker_add_server($worker, $host, $port);
gearman_worker_add_function($worker, $job, $func);

print "gearman_worker_work() (Procedural): ".(gearman_worker_work($worker) === true ? 'Success' : 'Failure') . PHP_EOL;

print "OK";

function do_work($job) {
	print "Calling function ".__FUNCTION__.PHP_EOL;
}
?>
--EXPECT--
GearmanWorker::doBackground() (OO): Success
Calling function do_work
GearmanWorker::work() (OO): Success
Calling function do_work
gearman_worker_work() (Procedural): Success
OK
tests/gearman_client_017.phpt000064400000003512150414423370012146 0ustar00--TEST--
GearmanClient::jobStatus(), gearman_client_job_status()
--SKIPIF--
<?php if (!extension_loaded("gearman")) print "skip";
require_once('skipifconnect.inc');
?>
--FILE--
<?php 

$job_name = uniqid();

$client = new GearmanClient();
$client->addServer('localhost', 4730);

$job_handle = $client->doBackground($job_name . "_OO", "test_jobStatus");
list($is_known, $is_running, $numerator, $denominator) = $client->jobStatus($job_handle);

print "GearmanClient::jobStatus() (OO): " . PHP_EOL
	. "  is_known is true: " . ($is_known === true ? 'Success' : 'Failure') .
	PHP_EOL
	. "  is_running is false: " . ($is_running=== false ? 'Success' : 'Failure') .
	PHP_EOL
	. "  Numerator is 0: " . ($numerator == 0 ? 'Success' : 'Failure') .
	PHP_EOL
	. "  Denominator is 0: " . ($denominator == 0 ? 'Success' : 'Failure') .
	PHP_EOL;

$client2 = gearman_client_create();
gearman_client_add_server($client2, 'localhost', 4730);

$job_handle = gearman_client_do_background($client2, $job_name .
	"_procedural", "test_jobStatus");
list($is_known, $is_running, $numerator, $denominator) =
	gearman_client_job_status($client2, $job_handle);

print "gearman_client_job_status() (Procedural): " . PHP_EOL
	. "  is_known is true: " . ($is_known === true ? 'Success' : 'Failure') .
	PHP_EOL
	. "  is_running is false: " . ($is_running === false ? 'Success' : 'Failure') .
	PHP_EOL
	. "  Numerator is 0: " . ($numerator == 0 ? 'Success' : 'Failure') .
	PHP_EOL
	. "  Denominator is 0: " . ($denominator == 0 ? 'Success' : 'Failure') .
	PHP_EOL;

print "OK";
?>
--EXPECT--
GearmanClient::jobStatus() (OO): 
  is_known is true: Success
  is_running is false: Success
  Numerator is 0: Success
  Denominator is 0: Success
gearman_client_job_status() (Procedural): 
  is_known is true: Success
  is_running is false: Success
  Numerator is 0: Success
  Denominator is 0: Success
OK
tests/gearman_client_integration_test_001.phpt000064400000004032150414423370015577 0ustar00--TEST--

--SKIPIF--
<?php
require_once('skipif.inc');
require_once('skipifconnect.inc');
?>
--FILE--
<?php

$host = 'localhost';
$port = '4730';

$job_name = uniqid();

$pid = pcntl_fork();
if ($pid == -1) {
	die("Could not fork");
} else if ($pid > 0) {
	// Parent. This should be the Worker
	$worker = new GearmanWorker();
	$worker->addServer($host, $port);

	print "addFunction: " . var_export(
		$worker->addFunction(
			$job_name,
			function($job) {
				print "workload: " . var_export($job->workload(), true) . PHP_EOL;
			}
		),
		true
	) . PHP_EOL;

	for($i=0; $i<6; $i++) {
		$worker->work();
	}

	print "unregister: " . var_export($worker->unregister($job_name), true) . PHP_EOL;

	// Wait for child
	$exit_status = 0;
	if (pcntl_wait($exit_status) <= 0) {
		print "pcntl_wait exited with error" . PHP_EOL;
	} else if (!pcntl_wifexited($exit_status)) {
		print "child exited with error" . PHP_EOL;
	}

	print "OK" . PHP_EOL;
} else {
	// Child. This is the Client
	$client = new GearmanClient();
	$client->addServer($host, $port);

	$job_types = ['doNormal', 'doHigh', 'doLow'];
	foreach ($job_types as $job_type) {
		$unique_key = "{$job_name}_{$job_type}";
		$workload = "Workload for $job_type";
		$handle = $client->$job_type($job_name, $workload, $unique_key);
	}

	// Background jobs can run into a race condition if they complete out of
	// order
	$job_types = ['doBackground', 'doHighBackground', 'doLowBackground'];
	foreach ($job_types as $job_type) {
		$unique_key = "{$job_name}_{$job_type}";
		$workload = "Workload for $job_type";
		$handle = $client->$job_type($job_name, $workload, $unique_key);

		do {
			usleep(10000);
			list($is_known, $is_running, $numerator, $denominator) =
				$client->jobStatus($handle);
		} while ($is_known === true || $is_running === true);
	}
}
?>
--EXPECT--
addFunction: true
workload: 'Workload for doNormal'
workload: 'Workload for doHigh'
workload: 'Workload for doLow'
workload: 'Workload for doBackground'
workload: 'Workload for doHighBackground'
workload: 'Workload for doLowBackground'
unregister: true
OK
tests/gearman_worker_013.phpt000064400000001472150414423370012200 0ustar00--TEST--
gearman_worker_add_function()
--SKIPIF--
<?php if (!extension_loaded("gearman")) print "skip";
require_once('skipifconnect.inc');
?>
--FILE--
<?php 

$host = 'localhost';
$port = 4730;
$job = 'GenericJob';
$func = 'do_work';

$worker = new GearmanWorker();
$worker->addServer($host, $port);
print "GearmanWorker::addFunction() (OO): ".($worker->addFunction($job, $func) ? "Success" : "Failure").PHP_EOL;

$worker2 = gearman_worker_create();
gearman_worker_add_server($worker, $host, $port);
print "gearman_worker_add_function() (Procedural): ".(gearman_worker_add_function($worker, $job, $func) ? "Success" : "Failure").PHP_EOL;

print "OK";

function do_work() {
	print "I'm in ".__FUNCTION__.PHP_EOL;
}
?>
--EXPECT--
GearmanWorker::addFunction() (OO): Success
gearman_worker_add_function() (Procedural): Success
OK
tests/skipifversion.inc000064400000000370150414423370011277 0ustar00<?php

$min_ver = '1.1.2';

$version_string= exec('gearmand -V');
$version = explode(' ', $version_string)[1];
if (version_compare($version, $min_ver, '<')) {
    die("skip requires gearmand version >= {$min_ver}, found version {$version}\n");
}


tests/gearman_client_integration_test_002.phpt000064400000002462150414423370015605 0ustar00--TEST--
GearmanClient::setStatusCallback(), gearman_client_set_status_callback(),
GearmanClient::addTaskStatus(), gearman_client_add_task_status(),
GearmanClient::runTasks(), gearman_client_run_tasks()
--SKIPIF--
<?php if (!extension_loaded("gearman")) print "skip";
require_once('skipifconnect.inc');
?>
--FILE--
<?php
function reverse_status($task, $context)
{
	print "In " . __FUNCTION__
		. " context is '$context'"
		. PHP_EOL;
}

$client = new GearmanClient();
$client->addServer('localhost');

$handle = $client->doBackground("reverse", "Hello World!");

$client->setStatusCallback("reverse_status");

$oo_context = "context passed in through OO";

$client->addTaskStatus($handle, $oo_context);

// Should print within reverse_status
$client->runTasks();

$client2 = gearman_client_create();
gearman_client_add_server($client2, 'localhost', 4730);

$handle = gearman_client_do_background($client2, "reverse", "Hello World!");

gearman_client_set_status_callback($client2, "reverse_status");

$procedural_context = "context passed in through procedural";

gearman_client_add_task_status($client2, $handle, $procedural_context);

gearman_client_run_tasks($client2);

print "OK";
?>
--EXPECT--
In reverse_status context is 'context passed in through OO'
In reverse_status context is 'context passed in through procedural'
OK
tests/gearman_job_integration_test_004.phpt000064400000002653150414423370015105 0ustar00--TEST--
Test GearmanJob::sendComplete()
--SKIPIF--
<?php
require_once('skipif.inc');
require_once('skipifconnect.inc');
?>
--FILE--
<?php
require_once('connect.inc');

print "Start" . PHP_EOL;

$job_name = uniqid();

$pid = pcntl_fork();
if ($pid == -1) {
    die("Could not fork");
} else if ($pid > 0) {
    // Parent. This is the worker
    $worker = new GearmanWorker();
    $worker->addServer($host, $port);
    $worker->addFunction(
        $job_name,
        function($job, $data) {
            print "GearmanJob::sendComplete (OO): "
                . ($job->sendComplete("Job is complete.") === true ? 'Success' : 'Failure')
                . PHP_EOL;
            }
    );

    $worker->work();

    $worker->unregister($job_name);

    // Wait for child
    $exit_status = 0;
    if (pcntl_wait($exit_status) <= 0) {
        print "pcntl_wait exited with error" . PHP_EOL;
    } else if (!pcntl_wifexited($exit_status)) {
        print "child exited with error" . PHP_EOL;
    }
} else {
    //Child. This is the client. Don't echo anything here
    $client = new GearmanClient();
    if ($client->addServer($host, $port) !== true) {
        exit(1); // error
    };

    $tasks = [];
    $tasks[] = $client->addTask($job_name, "normal");
    $client->runTasks();
    if ($client->returnCode() != GEARMAN_SUCCESS) {
        exit(2); // error
    }
    exit(0);
}

print "Done";
--EXPECTF--
Start
GearmanJob::sendComplete (OO): Success
Done
tests/gearman_job_integration_test_007.phpt000064400000002631150414423370015104 0ustar00--TEST--
Test GearmanJob::handle()
--SKIPIF--
<?php
require_once('skipif.inc');
require_once('skipifconnect.inc');
?>
--FILE--
<?php
require_once('connect.inc');

print "Start" . PHP_EOL;

$job_name = uniqid();

$pid = pcntl_fork();
if ($pid == -1) {
    die("Could not fork");
} else if ($pid > 0) {
    // Parent. This is the worker
    $worker = new GearmanWorker();
    $worker->addServer($host, $port);
    $worker->addFunction(
        $job_name,
        function($job, $data) {
            print "GearmanJob::handle (OO): "
                . (preg_match('/^(.*):(.*):(.*)$/',$job->handle()) ? 'Success' : 'Failure')
                . PHP_EOL;
            }
    );

    $worker->work();

    $worker->unregister($job_name);

    // Wait for child
    $exit_status = 0;
    if (pcntl_wait($exit_status) <= 0) {
        print "pcntl_wait exited with error" . PHP_EOL;
    } else if (!pcntl_wifexited($exit_status)) {
        print "child exited with error" . PHP_EOL;
    }
} else {
    //Child. This is the client. Don't echo anything here
    $client = new GearmanClient();
    if ($client->addServer($host, $port) !== true) {
        exit(1); // error
    };

    $tasks = [];
    $tasks[] = $client->addTask($job_name, "normal");
    $client->runTasks();
    if ($client->returnCode() != GEARMAN_SUCCESS) {
        exit(2); // error
    }
    exit(0);
}

print "Done";
--EXPECTF--
Start
GearmanJob::handle (OO): Success
Done
tests/gearman_task_001.phpt000064400000001446150414423370011627 0ustar00--TEST--
GearmanTask::functionName, gearman_task_function_name
--SKIPIF--
<?php if (!extension_loaded("gearman")) print "skip";
require_once('skipifconnect.inc');
?>
--FILE--
<?php 

$client = new GearmanClient();
$client->addServer('localhost', 4730);
$task = $client->addTask("GearmanTaskFunction", "normal");
print "GearmanTask::functionName (OO): " . $task->functionName() . PHP_EOL;

$client2 = gearman_client_create();
gearman_client_add_server($client2, 'localhost', 4730);
$task2 = gearman_client_add_task($client2, "GearmanTaskFunction2", "normal");
print "gearman_client_function_name (Procedural): "
	. gearman_task_function_name($task2) . PHP_EOL;

print "OK";
?>
--EXPECT--
GearmanTask::functionName (OO): GearmanTaskFunction
gearman_client_function_name (Procedural): GearmanTaskFunction2
OK
tests/gearman_worker_005.phpt000064400000000705150414423370012177 0ustar00--TEST--
gearman_worker_options()
--SKIPIF--
<?php if (!extension_loaded("gearman")) print "skip"; ?>
--FILE--
<?php 

$worker = new GearmanWorker();
print "GearmanWorker::options (OO): " . $worker->options() . PHP_EOL;

$worker2 = gearman_worker_create();
print "gearman_worker_options (Procedural): " . gearman_worker_options($worker2) . PHP_EOL;

print "OK";
?>
--EXPECT--
GearmanWorker::options (OO): 644
gearman_worker_options (Procedural): 644
OK
tests/gearman_job_integration_test_002.phpt000064400000002645150414423370015104 0ustar00--TEST--
Test GearmanJob::sendWarning()
--SKIPIF--
<?php
require_once('skipif.inc');
require_once('skipifconnect.inc');
?>
--FILE--
<?php
require_once('connect.inc');

print "Start" . PHP_EOL;

$job_name = uniqid();

$pid = pcntl_fork();
if ($pid == -1) {
    die("Could not fork");
} else if ($pid > 0) {
    // Parent. This is the worker
    $worker = new GearmanWorker();
    $worker->addServer($host, $port);
    $worker->addFunction(
        $job_name,
        function($job, $data) {
            print "GearmanJob::sendWarning (OO): "
                . ($job->sendWarning("Warning string") === true ? 'Success' : 'Failure')
                . PHP_EOL;
            }
    );

    $worker->work();

    $worker->unregister($job_name);

    // Wait for child
    $exit_status = 0;
    if (pcntl_wait($exit_status) <= 0) {
        print "pcntl_wait exited with error" . PHP_EOL;
    } else if (!pcntl_wifexited($exit_status)) {
        print "child exited with error" . PHP_EOL;
    }
} else {
    //Child. This is the client. Don't echo anything here
    $client = new GearmanClient();
    if ($client->addServer($host, $port) !== true) {
        exit(1); // error
    };

    $tasks = [];
    $tasks[] = $client->addTask($job_name, "normal");
    $client->runTasks();
    if ($client->returnCode() != GEARMAN_SUCCESS) {
        exit(2); // error
    }
    exit(0);
}

print "Done";
--EXPECTF--
Start
GearmanJob::sendWarning (OO): Success
Done
tests/gearman_worker_016.phpt000064400000003460150414423370012202 0ustar00--TEST--
GearmanWorker::addFunction(), context param
--SKIPIF--
<?php if (!extension_loaded("gearman")) print "skip";
require_once('skipifconnect.inc');
?>
--FILE--
<?php 
$host = 'localhost';
$port = 4730;
$job = 'AddFunctionArrCtxTest';
$workload = '{"workload":"test"}';

$client = new GearmanClient();
$client->addServer($host, $port);
$handle = $client->doBackground($job, $workload);
$client->doBackground($job, $workload);
$client->doBackground($job, $workload);
$client->doBackground($job, $workload);

print "GearmanWorker::doBackground() (OO): ".(preg_match('/^H:'.gethostname().':\d+$/', $handle) === 1? 'Success' : 'Failure').PHP_EOL;

$worker = new TestWorker();
print "GearmanWorker::work() (OO, array ctx): " .($worker->work() === true ? 'Success' : 'Failure') . PHP_EOL;
print "GearmanWorker::work() (OO, array ctx): " .($worker->work() === true ? 'Success' : 'Failure') . PHP_EOL;
print "GearmanWorker::work() (OO, array ctx): " .($worker->work() === true ? 'Success' : 'Failure') . PHP_EOL;


print "OK";

class TestWorker extends \GearmanWorker
{
    public function __construct()
    {
	global $job;
        parent::__construct();
        $this->addServer();
        $this->addFunction($job, [$this, 'test'], ['firstArg' => 'firstValue']);
    }

    public function test($job, $context)
    {
        echo "Starting job {$job->workload()}". PHP_EOL;
        $firstArg = $context['firstArg'];
        echo "FirstArg is $firstArg" . PHP_EOL;
    }
}

?>
--EXPECT--
GearmanWorker::doBackground() (OO): Success
Starting job {"workload":"test"}
FirstArg is firstValue
GearmanWorker::work() (OO, array ctx): Success
Starting job {"workload":"test"}
FirstArg is firstValue
GearmanWorker::work() (OO, array ctx): Success
Starting job {"workload":"test"}
FirstArg is firstValue
GearmanWorker::work() (OO, array ctx): Success
OK
tests/gearman_worker_012.phpt000064400000003732150414423370012200 0ustar00--TEST--
gearman_worker_register(), gearman_worker_unregister(), gearman_worker_unregister_all()
--SKIPIF--
<?php if (!extension_loaded("gearman")) print "skip";
require_once('skipifconnect.inc');
?>
--FILE--
<?php 

$host = 'localhost';
$port = 4730;
$registered_func = 'registered_function';

$worker = new GearmanWorker();
$worker->addServer($host, $port);

print "GearmanWorker::register() (OO): " . ($worker->register($registered_func) === true ? "Success" : "Failure") . PHP_EOL;
print "GearmanWorker::unregister() (OO): " . ($worker->unregister($registered_func) === true ? "Success" : "Failure") . PHP_EOL;
print "GearmanWorker::register() (OO): " . ($worker->register($registered_func) === true ? "Success" : "Failure") . PHP_EOL;
print "GearmanWorker::unregisterAll() (OO): " . ($worker->unregisterAll() === true ? "Success" : "Failure") . PHP_EOL;

$worker2 = gearman_worker_create();
gearman_worker_add_server($worker, $host, $port);

print "gearman_worker_register() (Procedural): " . (gearman_worker_register($worker, $registered_func) === true ? "Success" : "Failure") . PHP_EOL;
print "gearman_worker_unregister() (Procedural): " . (gearman_worker_unregister($worker, $registered_func) === true ? "Success" : "Failure") . PHP_EOL;
print "gearman_worker_register() (Procedural): " . (gearman_worker_register($worker, $registered_func) === true ? "Success" : "Failure") . PHP_EOL;
print "gearman_worker_unregister_all() (Procedural): " . (gearman_worker_unregister_all($worker) === true ? "Success" : "Failure") . PHP_EOL;

print "OK";

function registered_function() {
	print "I'm in ".__FUNCTION__.PHP_EOL;
}
?>
--EXPECT--
GearmanWorker::register() (OO): Success
GearmanWorker::unregister() (OO): Success
GearmanWorker::register() (OO): Success
GearmanWorker::unregisterAll() (OO): Success
gearman_worker_register() (Procedural): Success
gearman_worker_unregister() (Procedural): Success
gearman_worker_register() (Procedural): Success
gearman_worker_unregister_all() (Procedural): Success
OK

tests/gearman_client_007.phpt000064400000002262150414423370012146 0ustar00--TEST--
GearmanClient::addOptions(), gearman_client_add_options()
--SKIPIF--
<?php if (!extension_loaded("gearman")) print "skip"; ?>
--FILE--
<?php 

$client = new GearmanClient();
$client->setOptions(GEARMAN_CLIENT_NON_BLOCKING);
print "GearmanClient::options (OO): " . $client->options() . PHP_EOL;
print "GearmanClient::addOptions (OO): " . ($client->addOptions(GEARMAN_CLIENT_FREE_TASKS) ? 'Success' : 'Failure') . PHP_EOL;
print "GearmanClient::options (OO): " . $client->options() . PHP_EOL;

$client2 = gearman_client_create();
gearman_client_set_options($client2, GEARMAN_CLIENT_NON_BLOCKING);
print "gearman_client_options (Procedural): " . gearman_client_options($client2) . PHP_EOL;
print "gearman_client_add_options (Procedural): " . (gearman_client_add_options($client2, GEARMAN_CLIENT_FREE_TASKS) ? 'Success' : 'Failure') . PHP_EOL;
print "gearman_client_options (Procedural): " . gearman_client_options($client2) . PHP_EOL;

print "OK";
?>
--EXPECT--
GearmanClient::options (OO): 2
GearmanClient::addOptions (OO): Success
GearmanClient::options (OO): 34
gearman_client_options (Procedural): 2
gearman_client_add_options (Procedural): Success
gearman_client_options (Procedural): 34
OK
tests/gearman_client_013.phpt000064400000001214150414423370012137 0ustar00--TEST--
GearmanClient::addServers(), gearman_client_add_servers()
--SKIPIF--
<?php if (!extension_loaded("gearman")) print "skip";
require_once('skipifconnect.inc');
?>
--FILE--
<?php 

$client = new GearmanClient();
print "GearmanClient::addServer(OO): " . ($client->addServers('localhost,localhost:4730') ? 'Success' : 'Failure') . PHP_EOL;

$client2 = gearman_client_create();
print "gearman_client_add_servers (Procedural): " . (gearman_client_add_servers($client2, 'localhost,localhost:4730') ? 'Success' : 'Failure') . PHP_EOL;

print "OK";
?>
--EXPECT--
GearmanClient::addServer(OO): Success
gearman_client_add_servers (Procedural): Success
OK
tests/gearman_client_010.phpt000064400000002015150414423370012134 0ustar00--TEST--
GearmanClient::setTimeout(), gearman_client_set_timeout()
--SKIPIF--
<?php if (!extension_loaded("gearman")) print "skip"; ?>
--FILE--
<?php 

$client = new GearmanClient();
print "GearmanClient::timeout (OO): " . $client->timeout() . PHP_EOL;
print "GearmanClient::setTimeout (OO): " . ($client->setTimeout(3) ? 'Success' : 'Failure') . PHP_EOL;
print "GearmanClient::timeout (OO): " . $client->timeout() . PHP_EOL;

$client2 = gearman_client_create();
print "gearman_client_timeout (Procedural): " . gearman_client_timeout($client2) . PHP_EOL;
print "gearman_client_set_timeout (Procedural): " . (gearman_client_set_timeout($client2, 3) ? 'Success' : 'Failure') . PHP_EOL;
print "gearman_client_timeout (Procedural): " . gearman_client_timeout($client2) . PHP_EOL;

print "OK";
?>
--EXPECT--
GearmanClient::timeout (OO): -1
GearmanClient::setTimeout (OO): Success
GearmanClient::timeout (OO): 3
gearman_client_timeout (Procedural): -1
gearman_client_set_timeout (Procedural): Success
gearman_client_timeout (Procedural): 3
OK