网站需要永远加载,然后我得到" Uncaught SoapFault例外"

时间:2017-01-29 19:05:09

标签: php mysql soap

尝试使用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

肥皂客户端

<?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);
    }

?>

肥皂服务器

<?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();

?>

似乎有一些进程陷入无限循环或某事。但我无法弄清楚是什么或在哪里!

1 个答案:

答案 0 :(得分:0)

现在我们知道问题出在addUser函数中,让我们首先了解问题所在。

@ SoapServer.php 替换:

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

使用:

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

此外,在这两个文件中,向localhost uri添加斜杠。

更新1:

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

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)