1. Go to this page and download the library: Download maurice2k/multicurl library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
maurice2k / multicurl example snippets
use Maurice\Multicurl\{Manager, Channel, HttpChannel, Helper\Stream};
$urls = [
'https://www.google.com/',
'https://www.facebook.com/',
'https://www.amazon.com/',
'https://www.ebay.com/',
'https://www.example.org/',
'https://non-existant.this-is-a-dns-error.org/',
'https://www.netflix.com/',
'https://www.microsoft.com/',
];
$manager = new Manager(2); // allow two concurrent connections
// set defaults for all channels that are being instantiated using HttpChannel::create()
HttpChannel::prototype()->setConnectionTimeout(200);
HttpChannel::prototype()->setTimeout(5000);
HttpChannel::prototype()->setFollowRedirects(true);
HttpChannel::prototype()->setCookieJarFile('cookies.txt');
foreach ($urls as $url) {
$chan = HttpChannel::create($url);
$chan->setOnReadyCallback(function(Channel $channel, array $info, Stream $stream, Manager $manager) {
$length = $stream->getLength();
$streamContent = $stream->consume();
echo "[X] Successfully loaded '" . $channel->getURL() . "' (" . $length . " bytes, status code " . $info['http_code'] . ")\n";
});
$chan->setOnTimeoutCallback(function(Channel $channel, int $timeoutType, int $elapsedMS, Manager $manager) {
echo "[T] " . ($timeoutType == Channel::TIMEOUT_CONNECTION ? "Connection" : "Global") . " timeout after {$elapsedMS} ms for '" . $channel->getURL() . "'\n";
});
$chan->setOnErrorCallback(function(Channel $channel, string $message, $errno, array $info, Manager $manager) {
echo "[E] cURL error #{$errno}: '{$message}' for '" . $channel->getURL() . "'\n";
});
$manager->addChannel($chan);
}
$manager->run();
use Maurice\Multicurl\{Manager, Channel, HttpChannel, Helper\Stream};
$counter = new \stdClass();
$counter->links = 20;
$manager = new Manager(2); // allow two concurrent connections
$manager->setContext($counter);
$chan = new HttpChannel('https://en.wikipedia.org/wiki/Web_crawler');
$chan->setConnectionTimeout(500);
$chan->setTimeout(5000);
$chan->setFollowRedirects(true);
$chan->setCookieJarFile('cookies.txt');
$chan->setOnReadyCallback(function(Channel $channel, array $info, Stream $stream, Manager $manager) {
$length = $stream->getLength();
$streamContent = $stream->consume();
echo "[X] Successfully loaded '" . $channel->getURL() . "' (" . $length . " bytes)\n";
if ($manager->getContext()->links > 0) {
if (!preg_match_all('#<a[^>]+?href="(/wiki/[^:]+?)"[^>]*
use Maurice\Multicurl\Channel;
use Maurice\Multicurl\Manager;
use Maurice\Multicurl\McpChannel;
use Maurice\Multicurl\Mcp\RpcMessage;
$mcpUrl = 'https://remote.mcpservers.org/fetch/mcp';
$manager = new Manager();
$listToolsChannel = new McpChannel($mcpUrl, RpcMessage::toolsListRequest());
//$listToolsChannel->setShowCurlCommand(true);
//$listToolsChannel->setVerbose(true);
// Automatically initialize MCP channel (two more requests will be sent)
$listToolsChannel->setAutomaticInitialize();
// Set up MCP message handling for the tools/list response
$listToolsChannel->setOnMcpMessageCallback(function (RpcMessage $message, McpChannel $channel) use ($manager) {
echo "Received MCP Message (ID: {$message->getId()}, Type: {$message->getType()})\n";
if ($message->isResponse() && $message->getId() === $channel->getRpcMessage()->getId()) { // Response to tools/list request
if ($message->getResult() && isset($message->getResult()['tools'])) {
echo "Available Tools:\n";
foreach ($message->getResult()['tools'] as $tool) {
// Build function-like definition with parameters
$functionDef = $tool['name'];
if (isset($tool['inputSchema']) && isset($tool['inputSchema']['properties'])) {
$params = [];
foreach ($tool['inputSchema']['properties'] as $paramName => $paramProps) {
$type = $paramProps['type'] ?? 'mixed';
$
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.