E
E
Evgeny2015-08-13 20:16:11
linux
Evgeny, 2015-08-13 20:16:11

Why does file_get_contents hang without returning a result or error?

Good day to all!
The problem is the following:
there is a php code:

$url = 'https://www.topnotchinc.com/MyAccount/AccountHome.aspx';
$html = file_get_contents($url, false, stream_context_create(array(
    'http' => array(
    	'method'  => 'GET',
        'header'  => 'Cookie: ' . $this->cookies //тут просто строка с куками
    ),
    'ssl' => array(
        "verify_peer"=>false,
        "verify_peer_name"=>false,
       )
)));

This code works fine many times , but hangs stupidly many times + 1 .
The process has been hanging in state S for the third hour now:
$ ps -F 16724
UID        PID  PPID  C    SZ   RSS PSR STIME TTY      STAT   TIME CMD
parser2  16724     1  0 79404 73108   5 Aug10 ?        S     21:55 php -q parser5_tnd.php

$ netstat -an | grep 144.202.201.11
tcp        0      0 (ip сервера, на котором запущен скрипт):43877         144.202.201.11:443          ESTABLISHED

those. the connection has not been disconnected by timeout for three hours now, the timeout is set:
$ cat /etc/php.ini | grep default_socket_timeout
default_socket_timeout = 60

With the help of gdb, we managed to see the stack:
(gdb) bt
#0  0x00007f7c7b396740 in __read_nocancel () from /lib64/libpthread.so.0
#1  0x0000003a7e2de041 in ?? () from /usr/lib64/libcrypto.so.10
#2  0x0000003a7e2dc399 in BIO_read () from /usr/lib64/libcrypto.so.10
#3  0x0000003a7e62beff in ssl3_read_n () from /usr/lib64/libssl.so.10
#4  0x0000003a7e62c69c in ssl3_read_bytes () from /usr/lib64/libssl.so.10
#5  0x0000003a7e627ec0 in ?? () from /usr/lib64/libssl.so.10
#6  0x00000000004818a8 in php_openssl_sockop_read (stream=0x25b80d0, buf=0x3a22a48 "8*\242\003", count=<value optimized out>, tsrm_ls=0x21cfc40)
    at /root/rpmbuild/SOURCES/php-5.6.0/ext/openssl/xp_ssl.c:1810
#7  0x00000000007ff3ef in php_stream_fill_read_buffer (stream=0x25b80d0, size=126, tsrm_ls=0x21cfc40) at /root/rpmbuild/SOURCES/php-5.6.0/main/streams/streams.c:692
#8  0x000000000080014e in _php_stream_get_line (stream=0x25b80d0, buf=0x7fff4216f2b0 "", maxlen=127, returned_len=0x7fff4216f348, tsrm_ls=0x21cfc40)
    at /root/rpmbuild/SOURCES/php-5.6.0/main/streams/streams.c:975
#9  0x00000000007938b7 in php_stream_url_wrap_http_ex (wrapper=0x11040a0, path=0x7fff4216f348 "\230%p\002", mode=0xd78bac "rb", options=0, opened_path=0x0, 
    context=<value optimized out>, redirect_max=<value optimized out>, flags=1, tsrm_ls=0x21cfc40) at /root/rpmbuild/SOURCES/php-5.6.0/ext/standard/http_fopen_wrapper.c:683
#10 0x0000000000796482 in php_stream_url_wrap_http (wrapper=<value optimized out>, path=<value optimized out>, mode=<value optimized out>, options=<value optimized out>, 
    opened_path=<value optimized out>, context=<value optimized out>, tsrm_ls=0x21cfc40) at /root/rpmbuild/SOURCES/php-5.6.0/ext/standard/http_fopen_wrapper.c:951
#11 0x00000000007fe91b in _php_stream_open_wrapper_ex (path=0x2702598 "https://www.topnotchinc.com/MyAccount/AccountHome.aspx", mode=0xd78bac "rb", options=8, opened_path=0x0, 
    context=0x2f3e068, tsrm_ls=0x21cfc40) at /root/rpmbuild/SOURCES/php-5.6.0/main/streams/streams.c:2064
#12 0x0000000000759c9f in zif_file_get_contents (ht=3, return_value=0x25ae908, return_value_ptr=<value optimized out>, this_ptr=<value optimized out>, 
    return_value_used=<value optimized out>, tsrm_ls=0x21cfc40) at /root/rpmbuild/SOURCES/php-5.6.0/ext/standard/file.c:548
#13 0x000000000068caaf in phar_file_get_contents (ht=3, return_value=0x25ae908, return_value_ptr=0x7f7c7aa4fef8, this_ptr=0x0, return_value_used=1, tsrm_ls=0x21cfc40)
    at /root/rpmbuild/SOURCES/php-5.6.0/ext/phar/func_interceptors.c:225
#14 0x00000000008d995b in zend_do_fcall_common_helper_SPEC (execute_data=<value optimized out>, tsrm_ls=0x21cfc40) at /root/rpmbuild/SOURCES/php-5.6.0/Zend/zend_vm_execute.h:558
#15 0x00000000008c803b in execute_ex (execute_data=0x7f7c7aa4fff0, tsrm_ls=0x21cfc40) at /root/rpmbuild/SOURCES/php-5.6.0/Zend/zend_vm_execute.h:363
#16 0x000000000084ff87 in zend_execute_scripts (type=8, tsrm_ls=0x21cfc40, retval=0x0, file_count=3) at /root/rpmbuild/SOURCES/php-5.6.0/Zend/zend.c:1330
#17 0x00000000007e352b in php_execute_script (primary_file=0x7fff42172ca0, tsrm_ls=0x21cfc40) at /root/rpmbuild/SOURCES/php-5.6.0/main/main.c:2584
#18 0x0000000000902924 in do_cli (argc=3, argv=0x21cfb30, tsrm_ls=0x21cfc40) at /root/rpmbuild/SOURCES/php-5.6.0/sapi/cli/php_cli.c:994
#19 0x00000000009031ad in main (argc=3, argv=0x21cfb30) at /root/rpmbuild/SOURCES/php-5.6.0/sapi/cli/php_cli.c:1378

those. hangs on the __read_nocancel() call, but googling has turned up almost nothing about this.
Question: what is the problem and how to overcome it? In which direction to dig?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question