Apache / PHP server does not respond while doing SOAP request

1

I'm working on a PHP application that consumes a third-party Web Service through SOAP requests. But something that is messing up is that while one page is doing a SOAP request no other page responds. Is there a way to make the request retrieving possible exceptions but not locking the application?

    
asked by anonymous 30.03.2015 / 16:33

2 answers

9

You are probably using session_start , PHP crashes the session file ( LOCK ), even though you change the page the session is still the same and the session file is as well.

  

Note: Other page visitors are not affected by this (unless you share the session) because each visitor has their own session file.

How this occurs

  • You have requested the page http://localhost/sync-webservice.php , it uses session and its response time is an average of 10 seconds.

  • Before this 10 seconds (average time) ends the file used by the session will be locked.

  • When accessing http://localhost/profile.php for example (which also uses the session), the session_start function will wait for the session file to be unlocked.

  • / li>

What are session files?

Session files are used to save the data of a specific session, they are generated at the time of using the http://localhost/sync-webservice.php function and are usually saved in the http://localhost/profile.php folder as session_start(); for example.

In the content of the session file /tmp for example, contains the data that will be used in the variable /tmp/sess_2ognrumtg8pri1prd098r2vij0 , an example of content:

nome-da-sessao|a:5:{...}

Each time we start a session, if the file does not exist, it is generated, if it exists, it passes the data of the file to the variable sess_2ognrumtg8pri1prd098r2vij0 and locks the file for recording, page complete the response to the request the file is released for other requests to be able to use it.

Solution

There are several methods that we can use, but I'll refer to the simplest thing to do is $_SESSION . Note that we should only use this when we are not going to set any variable $_SESSION or use other session_write_close functions.

Example usage:

  • $_SESSION[...] = ...;

    <?php
    session_start();
    
    //Fazemos todas gravações necessárias
    $_SESSION['A'] = 1;
    
    //Liberamos a sessão do travamento de escrita
    session_write_close();
    
    /*
     A partir daqui não poderemos mais gravar nada na
     sessão, porém a leitura da variável '$_SESSION'
     ainda é acessível, pois ela é uma *super global*
     e já está setado os valores neste ponto
    */
    
    //Simulamos páginas "lentas", 15 segundos de espera (delay)
    sleep(15);
    
  • session_*

    <?php
    session_start();
    
    //Fazemos todas gravações necessárias
    $_SESSION['B'] = 1;
    
    print_r($_SESSION);
    

In this way the other pages will not have to wait for the sync-webservice.php page to finish processing in order to complete their execution.

    
10.04.2015 / 16:00
0

You can try thread, however, thread in PHP is difficult, and depends on other libs and hosting. I suggest creating a subdomain just to make soap requests.
I believe this will be enough not to catch other pages.
If it continues, try a cheaper server only for external soap requests.

    
30.03.2015 / 17:41