2

I have a class named webserviceCall.

This is my class structure :

Constructor --->

Initiate webservice clients and DB handler class and some properties :

public function __construct()
{

    $this->username = $GLOBALS['WEBSRVC']['username'];
    $this->password = $GLOBALS['WEBSRVC']['password'];
    $this->api      = $GLOBALS['WEBSRVC']['api'];

    $this->loginClient = new SoapClient(NULL, array(
          'location' => "http://domain.com/webservice/kks/server.php",
          'uri'      => "urn://test/webservice") );

    $this->booksClient = new SoapClient(null, array(
          'location' => "http://domain.com/webservice/kks/books.php",
          'uri'      => "urn://test/webservice"
        ));


    $this->shopClient  = new SoapClient(null, array(
          'location' => "http://domain.com/webservice/kks/newShop.php",
          'uri'      => "urn://test/webservice/shop"
        ) );


    $this->db = new dbHandler($GLOBALS['DBVAR']['dbn'], $GLOBALS['DBVAR']['usn'], $GLOBALS['DBVAR']['psw']);

    $this->param = self::freshLogin( $this->username, $this->password, $this->api);

}//__Construct

And there's a method for check Login, based on webservice needs:

protected function freshLogin($username, $password, $api)
{
    $currentInfo = $this->db->simple_search('webservice');

    $token = ( ($currentInfo[0]['token'] != '')  ? $currentInfo[0]['token'] : false );

    if( $token == false )
    {
        $token = $this->loginClient->__soapCall('authenticate', array($currentInfo[0]['username'], $currentInfo[0]['password'], $currentInfo[0]['api']) );

        //update token in table
        $updateToken = $this->db->update_single('webservice', 'token', $token, true, 'api', $api);

        return $token . '||' . $api;
    }//token is empty - first login

    else
    {
        $checkToken = $this->loginClient->__soapCall('checkToken', array($token, $api) );

        if( isset($checkToken) && $checkToken > 0 )
        {
            return $token . '||' . $api;   
        }//if token is valid

        else
        {
            $token = $this->loginClient->__soapCall('authenticate', array($currentInfo[0]['username'], $currentInfo[0]['password'], $currentInfo[0]['api']) );

            //update token in table
            $updateToken = $this->db->update_single('webservice', 'token', $token, true, 'api', $api);

            return $token . '||' . $api;   
        }//authenticate again, save token and create param value

    }//token exists
}//function freshLogin

And finally, there's a method for transact webservice :

public function getBooks()
{
    return $this->booksClient->__soapCall('getAllBooks', array($this->param) );    
}//function getAllBooks

When I check getBooks() function with getAllBooks method, it seems the browser is waiting for the response, and there's no result. This is error:

Maximum execution time of 30 seconds exceeded in C:\xampp\htdocs\ketabTheme\PHP\classes\webserviceCall.php on line 114

But When I check exactly the same request in another file, out of a class, it's OK. Besides, when I call another method of webservice inside getBooks method, again everything is fine.

Would you please help me to find out what's wrong here?

Note : getBooks method should have an array with 1935 index in result.





UPDATE : When I check this request in another file outside a class, this is the request-response timeline :

enter image description here

1 Answer 1

0

When you say "But When I check exactly the same request in another file, out of a class, it's OK.", how long does it take?

You should try increasing the max_execution_time in the php.ini file or by setting: ini_set('max_exeution_time', 60 /*seconds*/) in your PHP script?

2
  • Thanks for your guide. It seems you're on the right point. because I did limit the result to 10, and it's fine, but I set max_execution_time to 1800, and I didn't get any result after half an hour. Do you know, what's wrong and what should I change to fix this situation?
    – Kiyarash
    Oct 3, 2015 at 3:09
  • It depends on your code, you have to target the code that slows it all by using the least code you can to the whole code .... Oct 3, 2015 at 6:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.