PHP taking extra 1 second to retrieve each result set from Sphinx(!!) - php

I'm running into a strange issue.... This all worked fine last night when I coded the damn thing, but I reinstalled WAMP on my local dev server and now I'm running into problems.
I'm attempting to retrieve results from Sphinx through the PHP api. I'm just executing the most basic of queries as a test...
$searchtest = Sphinx::factory();
$results = $searchtest->Query('');
And $results contains the sphinx results as expected
...
[total] => 1000
[total_found] => 30312
[time] => 0.004
However, when I profile this small piece of code, it's telling me that PHP is taking an extra second to process the query!
test (1) - 1.066703 s
The problem gets worse on my production code which runs several Sphinx searches, yesterday... everything was running fine and each search took 0.004sec (or an equally small amount of time) but today, the page takes several seconds to run all the search queries! (this is on an isolated dev server, so no traffic issues)
results (1) - 1.046128 s
sidebar_data (1) - 10.388812 s
featured (1) - 1.034211 s
Each separate query to the Sphinx daemon takes an extra second to come back! (sidebar_data hits the search server 10 times)
What is going on here? I've wasted a bunch of time trying to figure it out and I'm stumped. I even reinstalled Sphinx from scratch. Since sphinx itself is reporting [time] => 0.004 fast access times, is the problem something to do with PHP?
What should I do to diagnose the problem?
Edit: I looked at the output from searchd --console, sure enough, it confirms that the search queries are quite quick to run, but if you look at the time, they are being executed approx. one per second... PHP is causing some delay somehow(??)
[Sun May 8 09:57:29.923 2011] 0.012 sec [all/1/ext 15039 (0,25)] [main]
[Sun May 8 09:57:30.996 2011] 0.020 sec [all/1/rel 30 (0,20) #city] [main]
[Sun May 8 09:57:32.034 2011] 0.016 sec [all/1/rel 50 (0,20) #make] [main]
[Sun May 8 09:57:33.061 2011] 0.015 sec [all/1/rel 15 (0,20) #style] [main]
[Sun May 8 09:57:34.099 2011] 0.017 sec [all/1/rel 25 (0,20) #colour] [main]
[Sun May 8 09:57:35.122 2011] 0.009 sec [all/1/rel 1 (0,20) #field] [main]
[Sun May 8 09:57:36.145 2011] 0.011 sec [all/2/rel 1 (0,20) #field] [main]
[Sun May 8 09:57:37.174 2011] 0.010 sec [all/2/rel 1 (0,20) #field] [main]
[Sun May 8 09:57:38.187 2011] 0.003 sec [all/2/rel 431 (0,20)] [main]
[Sun May 8 09:57:39.240 2011] 0.005 sec [all/2/rel 12627 (0,20)] [main]
[Sun May 8 09:57:40.292 2011] 0.005 sec [all/2/rel 13021 (0,20)] [main]
[Sun May 8 09:57:41.343 2011] 0.001 sec [all/3/rel 200 (0,20)] [main]

At a first look I'd have guessed some kind of DNS resolution problem could be involved but it seems like your running searchd on the same host as PHP
Rather than poke around trying to guess what is causing this I would recommend profiling the PHP code running on the machine. I would install xdebug, enable profiling and then analyse the output in webcachegrind. It should be able to point you to which functions are slow to run and give you a better clue as to what's wrong.

Related

error: out of memory / the connection was reset

I am trying to do a massive select * { insert into..} on a php page using xampp (v 5.5.30) on windows (64bit, 4 Gb ram).
After a few minutes I however get either two error messages:
A) "the connection was reset" in the browsers, or sometimes:
B) "mysql_query(): (HY000/2008): Out of memory..." during the insertion query.
On both occasions the PHP script itself is halted even using the directive:
ignore_user_abort(true);
I can't figure out why this is happening. Things I tried so for:
1) added in my apache config file:
<IfModule mpm_winnt_module> ThreadStackSize 8388608 </IfModule> because in the error log I noticed the line at the time of the connection reset:
[Mon Dec 07 13:01:23.540742 2015] [mpm_winnt:notice] [pid 2344:tid
504] AH00428: Parent: child process 4036 exited with status 3221225477
-- Restarting.
[Mon Dec 07 12:09:39.584814 2015] [mpm_winnt:notice] [pid 1684:tid
528] AH00354: Child: Starting 150 worker threads.
It seems like this error is linked to my problem in some way. Changing the config file however did not help and the error still appears.
2) Changed php ini setting:
ini_set("memory_limit","750MB");
3) Removed all mysql cache using:
RESET QUERY CACHE
4) Set PHP timeout:
set_time_limit(60*60);
The error occurs after a few minutes already.
Additional note: the filesize of the table used in the main select-query (mytable.MYD) is 400Mb, of which I only use a few columns of in the select. Once the query is loaded in the PHP memory, before executing the while loop, the memory footprint is 60Mb (using memory_get_usage())
Any idea what I can do to solve this?
thanks
You have to set execution time also.
set execution time to 0,it is functionally equivalent to turning the execution limit off completely:
ini_set('max_execution_time', 0);
Hope it will solve your problem

Apache error log: zend_mm_heap corrupted, child process exited with status 1 -- Restarting

I have seen some topics about 'zend_mm_heap' corrupted and 'child process exited with status nnnnn' but none of this topics lead to a solution. What does status 1 means in clear text, it is not clear what exactly happen.
Symptoms
This problem does not occur when the site is running without being logged in. Only when I logged in the problem sometimes happen when refreshing the page. Strange is that sometimes the html fails to load and sometimes resources like a CSS file or JS file. I also have seen that some resources take 6 seconds to 10 seconds to load. I think this is caused by restarting the server because of this error.
When above symptoms occur, the following (similar) info is written to the error.log file:
Error in error.log file:
zend_mm_heap corrupted
[Sun Feb 09 03:56:57 2014] [notice] AH00428: Parent: child process exited with status 1 -- Restarting.
[Sun Feb 09 03:56:57 2014] [notice] AH00455: Apache/2.4.3 (Win64) configured -- resuming normal operations
[Sun Feb 09 03:56:57 2014] [notice] AH00456: Server built: Aug 18 2012 14:13:48
[Sun Feb 09 03:56:57 2014] [notice] AH00418: Parent: Created child process 3460
[Sun Feb 09 03:56:57 2014] [notice] AH00354: Child: Starting 64 worker threads.
Configuration:
Intel I7 (Quadcore) chipset, 16GB RAM
Running latest XAMMP (or Z-WAMP, in both the same problem - see for Z-WAMP also http://zwamp.sourceforge.net/) on Windows 7 64 bit
Running APC -
For example:
Normal feedback (when problem does not occur):
What I want to know
Does have somebody info about Apache status 1 exit?
Am I able to debug this, how can I debug this?
There is a problem with APC (I use version 1.3.1) that cause this error, corrupt memory for some reason. I believe it has something do with session data because the problems only occur when logged in. My PHP class uses only a session when it is required to be logged in to be able to view the page. I have also checked my code but there is nothing abnormal or incomplete.
When I turn off the Windows extension php_apc.dll in the php.ini file everthing is working fine. No memory corruption and no delays. Also tried other cache extensions like xCache, eAccelerator, memcache and loads normally.
So I qualify this as a bug.

60 sec timeout, unable to find the right param to fix it

My website exits (error 500) if a script takes more than 60 sec to be executed, but i don't understand why.
Phpinfo:
max_execution_time = 600
max_input_time = 600
In my httpd.conf file:
timeout = 600
So i don't get how to increase this parameter.
I found in my phpinfo (but i have no idea if it's related or not):
default_socket_timeout = 60
mysql.connect_timeout = 60
I think the mysql.connect_timeout is not related at all (i got the error on a page with a sleep(65); only...)
I finaly found the answer !
I will share the answer since i think it may help someone else !
I found in the apache error_log the following :
[Tue Jul 09 15:17:47 2013] [warn] [client 212.198.111.252] mod_fcgid: read data timeout in 45 seconds
[Tue Jul 09 15:17:47 2013] [error] [client 212.198.111.252] Premature end of script headers: test_max_execution.php
I then modified a file located in /etc/httpd/conf.d/ named fcgid.conf
I increased 3 parameters (FcgidIOtimeout, FcgidIdleTimeout & FcgidConnectTimeout) and everything seems to work properly now !
Have a nice day and thank you for paying attention to my question !
Frederic
Have a look at…
PHP set_time_limit()
PHP Runtime Configuration
…and:
MySQL server has gone away - in exactly 60 seconds
Happy reading :-)

Unexpected server reset with php and apache

I have an application which interacts with a database. Suddenly and occasionally, pages are showing me Server connection Reset error in my Web browser. More surpisingly, accessing on a localhost page is triggering an alert on avast.
If I refresh pages using Ctrl+R, it happens occasionally. PHP is not showing any error messages, and it seems like the server is taking more time to respond than usual.
I am using wamp with apache 2.4, PHP 5.4.3. I am clueless as to where to start debugging or where to the problem is.
[Sun May 13 13:01:14 2012] [warn] Init: Session Cache is not configured [hint: SSLSessionCache]
[Sun May 13 13:01:14 2012] [notice] Apache/2.2.22 (Win32) mod_ssl/2.2.22 OpenSSL/0.9.8x configured -- resuming normal operations
[Sun May 13 13:01:14 2012] [notice] Server built: May 13 2012 12:51:11
[Sun May 13 13:01:14 2012] [notice] Parent: Created child process 3660
Apache server interrupted...
arn] Init: Session Cache is not configured [hint: SSLSessionCache]
[Sun May 13 13:01:15 2012] [notice] Child 3660: Child process is running
[Sun May 13 13:01:15 2012] [notice] Child 3660: Acquired the start mutex.
[Sun May 13 13:01:15 2012] [notice] Child 3660: Starting 64 worker threads.
[Sun May 13 13:01:15 2012] [notice] Child 3660: Starting thread to listen on port 80.
[Sun May 13 13:01:15 2012] [notice] Child 3660: Starting thread to listen on port 80.
[Sun May 13 13:01:28 2012] [notice] Parent: Received shutdown signal -- Shutting down the server.
[Sun May 13 13:01:28 2012] [notice] Child 3660: Exit event signaled. Child process is ending.
[Sun May 13 13:01:29 2012] [notice] Child 3660: Released the start mutex
[Sun May 13 13:01:30 2012] [notice] Child 3660: All worker threads have exited.
[Sun May 13 13:01:30 2012] [notice] Child 3660: Child process is exiting
[Sun May 13 13:01:30 2012] [notice] Parent: Child process exited successfully.
UPDATE:
When 'connection request' occurs if is use cachegrind it shows partial list of callstack of methods. means it does not run all the code. it is showing some require_once calls and that it. next time if i retry to get the page, page executes and shows the whole callstack.
When 'connection request occurs' it shows
18 different functions called in milliseconds (1 runs, 18 shown)
after retrying
220 different functions called in 329 milliseconds (2 runs, 220 shown)
I dont know why it is showing 2 runs. also it is taking more time to execute page. before it was doing it less than 100 ms.
Restart you computer and close/disable all running applications including anti-virus keeping only a minimal set of running applications. Close everything even those applications that you are sure can't interfere - you never know..
Make sure PHP shows all errors/warnings:
error_reporting(E_ALL);
ini_set('display_errors', '1');
Make sure you review every warning you receive from PHP. It may give you a clue.
Try to isolate a problem. Comment a chunk of code you suspect to cause the problem. Keep commenting until stop receive the error. Then start uncommenting until you find a problematic place. This way you can isolate a problematic code and once you see it, you may understand the problem.
Add lots of statements that will write to log file (or just echo). Then you can analyze the log file and understand at which point error happens helping you to isolate the problem...
Eventually you will find the problematic code block and will be able to track the problem. Hopefully :)
to restart Apache via PHP use the follow code in PHP
exec('/etc/init.d/httpd graceful');
and also look in the manual... and change the path to your httpd
Change apache listen port from 80 to 8080
file httpd.conf , change listen 80 to listen 8080 and restart apache
Re-try disabling temporarly the antivirus
Maybe it is not a right solution, but why not just try other WAMP version or maybe setup your system clock correct?. And have you tried to run Apache in minimal configuration? You may disable all extensions and modules (inc php itself) and if web server will work as expected you may turn one by one you modules. I don't know about your environment but you may also try to change working threads number and other values to minimal. I bet it doesn't help but at least you'll try.
If you have mod_security enabled try disabling and see if the same happens.. sometimes you can have over vigilant mod_security that will just go to http fail (sometimes can be as simple as inserting data with an ampersand into the database) and won't write any error to the server logs making it hard to troubleshoot, sounds similar to what you're experiencing, I would disable mod_security re-start server and see if the behavior has stopped!
It looks like some other people have encountered the same issue using Wamp:
Have you gone through each of the points enumerated in this post belonging to the official forum:
http://forum.wampserver.com/read.php?2,67660
Are you sure you don't have an include/require loop ?
That kind of loop make PHP eat up too much memory and apache kill itself to avoid it.
Or maybe some kind of 404 loop error ...
That kind of loop can happen if you have 404 errors sometimes. Here is an example :
You have a layout with an image which is missing, so it triggers a 404 errors. To display the page, the 404 errors add the layout around the error page which contains the missing image, which triggers another 404 errors.
Hope that helps.

PHP web server in PHP?

i.e to replace Apache with a PHP application that sent back html files when http requests for .php files are sent?
How practical is this?
It's already been done but if you want to know how practical it is, then i suggest you install and test with Apache bench to see the results:
http://nanoweb.si.kz/
Edit, A benchmark from the site:
Server Software: aEGiS_nanoweb/2.0.1-dev
Server Hostname: si.kz
Server Port: 80
Document Path: /six.gif
Document Length: 28352 bytes
Concurrency Level: 20
Time taken for tests: 3.123 seconds
Complete requests: 500
Failed requests: 0
Broken pipe errors: 0
Keep-Alive requests: 497
Total transferred: 14496686 bytes
HTML transferred: 14337322 bytes
Requests per second: 160.10 [#/sec] (mean)
Time per request: 124.92 [ms] (mean)
Time per request: 6.25 [ms] (mean, across all concurrent requests)
Transfer rate: 4641.91 [Kbytes/sec] received
Connnection Times (ms)
min mean[+/-sd] median max
Connect: 0 0 1.9 0 13
Processing: 18 100 276.4 40 2739
Waiting: 1 97 276.9 39 2739
Total: 18 100 277.8 40 2750
Percentage of the requests served within a certain time (ms)
50% 40
66% 49
75% 59
80% 69
90% 146
95% 245
98% 449
99% 1915
100% 2750 (last request)
Apart from Nanoweb, there is also a standard PEAR component to build standalone applications with a built-in webserver:
http://pear.php.net/package/HTTP_Server
Likewise the upcoming PHP 5.4 release is likely to include an internal mini webserver which facilitates simple file serving. https://wiki.php.net/rfc/builtinwebserver
php -S localhost:8000
Why reinvent the wheel? Apache or any other web server has had a lot of work put into it by a lot of skilled people to be stable and to do everything you wanted it to do.
Just FYI, PHP 5.4 just released with in-built webserver. Now you can run a local server with very simple commands like -
$ cd ~/public_html
$ php -S localhost:8000
And you'll see the requests and responses like this -
PHP 5.4.0 Development Server started at Thu Jul 21 10:43:28 2011
Listening on localhost:8000
Document root is /home/me/public_html
Press Ctrl-C to quit.
[Thu Jul 21 10:48:48 2011] ::1:39144 GET /favicon.ico - Request read
[Thu Jul 21 10:48:50 2011] ::1:39146 GET / - Request read
[Thu Jul 21 10:48:50 2011] ::1:39147 GET /favicon.ico - Request read
[Thu Jul 21 10:48:52 2011] ::1:39148 GET /myscript.html - Request read
[Thu Jul 21 10:48:52 2011] ::1:39149 GET /favicon.ico - Request read

Categories