gpt4 book ai didi

php - 网站需要永远加载然后我得到 "Uncaught SoapFault exception"

转载 作者:行者123 更新时间:2023-11-30 22:05:27 25 4
gpt4 key购买 nike

尝试使用 soap 服务将数据发送到 sql 数据库。但我的网站只加载 30 秒后出现此错误:

Warning: Uncaught SoapFault exception: [HTTP] Error Fetching http headers in soapclient.php Stack trace: #0 
[internal function]: SoapClient->__doRequest('__call('addUser', Array) #2 {main} thrown in soapclient.php


Fatal error: Maximum execution time of 30 seconds exceeded in soapclient.php on line 30

SOAP 客户端

<?php

$first_name = $_POST['first_name'];
$last_name = $_POST['last_name'];
$username = $_POST['username'];
$password = md5($_POST['password']);

$options = array('location' => "http://localhost/fellotest/soap/soap_client.php",
'uri' => 'http://localhost',
'trace'=>1);

ini_set('default_socket_timeout', 120)

try{
$client = new SoapClient(null, $options);
$client->addUser($first_name, $last_name, $username, $password);
}
catch(SoapFault $ex){
echo "FAULT </br>";
var_dump($client->__getLastRequest());
var_dump($client->__getLastResponse());
var_dump($ex);
}

?>

SOAP 服务器

<?php

include('helpers\security.php');
include('includes\shared\ez_sql_core.php');
include('includes\mysqli\ez_sql_mysqli.php');

// Setting up Soap Service
$options = array('uri' => 'http://localhost');
$server = new SoapServer(null, $options)

//connecting and adding a user to database
function addUser($first_name, $last_name, $username, $password){

// For security reasons
$info = new security();

// Connect to database
$db = new ezSQL_mysqli($info::$user, $info::$password, $info::$dbName, $info::$host);
if(!$db){
die('Could not connect to database');
}
// add user to database
$insert = $db->query("INSERT INTO `user`(`first_name`, `last_name`, `username`, `password`) VALUES ('$first_name', '$last_name', '$username', '$password')");
if(!$insert){
echo "Error while registering";
}
else{
echo "Register Successful";
}
}

// To handle client
$server->handle();

?>

似乎有一些进程陷入了无限循环之类的。但我不知道是什么或在哪里!

最佳答案

既然我们知道问题出在 addUser 函数中,那么让我们从了解问题出在哪里开始。

@SoapServer.php替换:

   // To handle client
$server->handle();

与:

$server->addFunction("addUser");
try {
$server->handle();
}
catch (Exception $e) {
$server->fault('Sender', $e->getMessage());
}

此外,在这两个文件中,向本地主机 uri 添加一个斜杠。

更新 1:

注释掉函数中的所有 block 代码。所以只有:

function addUser($first_name, $last_name, $username, $password){
return 1;
}

更新 2:

由于您仍然收到错误,请注释掉这些行:

include('helpers\security.php');
include('includes\shared\ez_sql_core.php');
include('includes\mysqli\ez_sql_mysqli.php');

更新 3:

仍然出现错误,SOAPSERVER 的路径错误或已关闭。在 soapclient.php 中考虑以下内容:

    // Add another option to the array.
$options = array( .... .....,
'connection_timeout' => 300);

//Cache
ini_set('soap.wsdl_cache_enabled',0);
ini_set('soap.wsdl_cache_ttl',0);

//And also increase the default_socket_timeout.
ini_set('default_socket_timeout', 300)

关于php - 网站需要永远加载然后我得到 "Uncaught SoapFault exception",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41924810/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com