about what is Sphinx here I do not introduce you can Baidu check, the following I would like to introduce is about PHP Sphinx Long connection Problem resolution, I hope that some of the articles to help you friends.
Sphinxclient::open
(PECL Sphinx >= 1.0.3)
sphinxclient::open-establishing a persistent connection to the search server
Description
public bool Sphinxclient::open (void)
Establish a persistent connection to the search service side.
Parameters
This function has no arguments.
return value
Returns TRUE on success, or FALSE on failure.
Today in the PHP system code optimization, the long connection to Sphinx to do some analysis found that PHP Sphinx API is not as we imagined in PHP-FPM fastcgi state has been with the Sphinx process to maintain a long connection, The open () method in the Sphinx API interface provides only one session request to ensure that multiple Sphinx calls are shared with a Sphinx TCP connection channel in a single PHP process, and when the PHP interpretation is complete, the connection to the Sphinx is automatically disconnected, rather than maintaining the connection status.
This post also confirms the landlord's idea: http://sphinxsearch.com/forum/view.html?id=7200
> So it seems, the definition of ' persistent connection ' in Sphinx was different from
> Persistent MYSQL connections when using a PhP api:the persistence are only across
> Multiple calls *in the same PHP request execution* and not persistence within the client
> process i.e. across multiple PHP requests.
We can do an experiment like this to prove my point:
Add the sphinx.so extension to PHP and write the following test code:
$s = new sphinxclient ();
Var_dump ($s);
$s->setserver (' 192.168.1.108 ', ' 9312 ');
$s->open ();
Var_dump ($s->query (' abxxxx '));
Var_dump ($s->query (' abxxxx '));
Note that here $s->open () is masked first, and then we execute this PHP script in the CLI state using the Strace command, which collects the system call information and discovers:
There were two requests for connect to 192.168.1.108 in the system call. In other words, when the open method is not called, it causes two TCP requests to Sphinx in the same PHP runtime.
611 Fcntl64 (3, F_SETFL, o_rdonly| O_nonblock) = 0
612 Connect (3, {sa_family=af_inet, sin_port=htons (9312), sin_addr=inet_addr ("192.168.1.108")}, +) = 1 einprogress ( Operation now in progress)
613 Select (4, NULL, [3], NULL, {0}) = 1 (out [3], left {59, 999996})
614 Fcntl64 (3, F_SETFL, o_rdonly) = 0
615 Send (3, "1", 4, msg_nosignal) = 4
616 recv (3, "1", 4, 0) = 4
617 Send (3, "1312241", +, msg_nosignal) = 16
618 Send (3, "246abxx" ..., msg_nosignal) = 140
619 recv (3, "131", 8, 0) = 8
620 recv (3, "25title4text2" ..., 96, 0) = 96
621 Close (3)
。。。。。。。。。。。。。。。。。。。
。。。。。。。。。。。。。。。。。。。
756 socket (pf_inet, sock_stream, ipproto_ip) = 3
757 Fcntl64 (3, F_SETFL, o_rdonly| O_nonblock) = 0
758 Connect (3, {sa_family=af_inet, sin_port=htons (9312), sin_addr=inet_addr ("192.168.1.108")}, +) = 1 einprogress ( Operation now in progress)
759 Select (4, NULL, [3], NULL, {0}) = 1 (out [3], left {59, 999997})
760 Fcntl64 (3, F_SETFL, o_rdonly) = 0
761 Send (3, "1", 4, msg_nosignal) = 4
762 recv (3, "1", 4, 0) = 4
763 Send (3, "1312241", +, msg_nosignal) = 16
764 Send (3, "246abxx" ..., msg_nosignal) = 140
765 recv (3, "131", 8, 0) = 8
766 recv (3, "25title4text2" ..., 96, 0) = 96
767 Close (3) = 0
768 Write (1, "Array (9) {n", 11array (9) {
Then we cancel the open call comment, continue to strace, we will find that this is still a continuous call two times the query method, but after the first query call the API will not immediately close the TCP connection, but continue to the second query call to use.
611 Fcntl64 (3, F_SETFL, o_rdonly| O_nonblock) = 0
612 Connect (3, {sa_family=af_inet, sin_port=htons (9312), sin_addr=inet_addr ("192.168.1.108")}, +) = 1 einprogress ( Operation now in progress)
613 Select (4, NULL, [3], NULL, {0}) = 1 (out [3], left {59, 999996})
614 Fcntl64 (3, F_SETFL, o_rdonly) = 0
615 Send (3, "1", 4, msg_nosignal) = 4
616 recv (3, "1", 4, 0) = 4
617 Send (3, "441", msg_nosignal) = 12
618 Select (4, [3], NULL, [3], {0, 0}) = 0 (Timeout)
619 Send (3, "1312241", +, msg_nosignal) = 16
620 Send (3, "246abxx" ..., msg_nosignal) = 140
621 recv (3, "131", 8, 0) = 8
622 recv (3, "25title4text2" ..., 96, 0) = 96
623 Write (1, "Array (9) {n", 11array (9) {
624) = 11
http://www.bkjia.com/PHPjc/632903.html www.bkjia.com true http://www.bkjia.com/PHPjc/632903.html techarticle about what is sphinx here I do not introduce you can Baidu check, the following I would like to introduce is about PHP Sphinx Long connection Problem resolution, I hope that some of the articles to help you friends. ...