-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
workman没有正确设置sapi_globals_struct的request_info #1040
Comments
那么问题来了,PHP cli里如何正确设置 sapi_globals_struct的request_info ? |
已经通过改写实现soapserver的功能,手动判断是否有wsdl的请求,如有则返回wsdl文件内容。 <?php
use Workerman\Worker;
use Workerman\Protocols\Http\Request;
use Workerman\Protocols\Http\Response;
use Workerman\Connection\TcpConnection;
require_once __DIR__ . '/vendor/autoload.php';
// 创建一个Worker监听2345端口,使用http协议通讯
$http_worker = new Worker("http://0.0.0.0:2345");
// 将屏幕打印输出到Worker::$stdoutFile指定的文件中
Worker::$stdoutFile = 'stdout.log';
// 设置进程名称
$http_worker->name = 'SoapServerWorker';
// 启动4个进程对外提供服务
$http_worker->count = 1;
class SoapServ {
public function sayHello($name) {
return "Hello, " . $name;
}
}
// 当有客户端连接时
$http_worker->onConnect = function ($connection) {
echo "新连接:{$connection->id}\n";
};
// 接收到浏览器发送的数据时回复hello world给浏览器
$http_worker->onMessage = function(TcpConnection $connection, Request $request)
{
if ($request->path() == '/serv') {
try {
// ini_set('display_errors', 'On');
// ini_set('soap.wsdl_cache_enabled', "0"); //关闭wsdl缓存
$wsdl = file_get_contents('/var/www/interfacems/workman/webman.wsdl');
if ($request->method() == 'GET' && $request->get('wsdl') !== null) {
$response = new Response(200, [
'Content-Type' => 'application/xml; charset=utf-8',
], $wsdl);
$connection->send($response);
return;
}
$server = new SoapServer('/var/www/interfacems/workman/webman.wsdl', array('soap_version' => SOAP_1_2));
$server->setClass('SoapServ');
ob_start();
$server->handle();
// readfile('webman.wsdl');
$ret = ob_get_clean();
$response = new Response(200, [
'Content-Type' => 'text/xml; charset=utf-8',
], $ret);
$connection->send($response);
return;
} catch (Exception $e) {
// 错误处理逻辑
$connection->send("Error: " . $e->getMessage());
}
} elseif ($request->path() == '/client') {
try {
$client = new SoapClient("http://localhost:8080/serv?wsdl");
$fs = $client->__getFunctions();
// 向浏览器发送hello world
$response = new Response(200, [
'Content-Type' => 'text/json; charset=utf-8',
], json_encode($fs, JSON_UNESCAPED_UNICODE));
$connection->send($response);
} catch (Exception $e) {
// 错误处理逻辑
$connection->send("Error: " . $e->getMessage());
}
} else {
// 如果不是预期的路径,可以发送404响应或其他逻辑
$connection->send("Not Found");
}
};
// 运行worker
Worker::runAll(); |
结论是啥 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
问题描述
使用workman框架,写一个简单的soap服务,访问wsdl无法正常获取服务定义的xml内容。经调试后发现workman收到请求后没有正确设置
sapi_globals_struct.request_info
程序代码或配置
workman代码
调试soap代码 soap.c:1158
输出:
操作系统环境及workerman/webman等具体版本
workman版本信息:
"workerman/workerman": "^4.1"
操作系统环境信息:
The text was updated successfully, but these errors were encountered: