Welcome! Log In Create A New Profile

Advanced

PHP - only seems to run one instance?

Posted by bigjme 
PHP - only seems to run one instance?
March 05, 2015 04:57PM
Hi everyone,

so i am setting up a standalone web server using nginx, php 5.6.6, and mysql. This is on windows, and nothing is a service. It is windows for a reason, but i know linux is better and more preferred.

This is currently all working and seems to function fine except for one issue. If i load certain pages (in a test drupal install) the php service or nginx seems to stop entirely.

The page runs for 32 seconds before loading (if i chang the php execution time to 30 seconds it throws a timeout error) but whilst this is loading, no other webpages will load, even though they usually load in around 7ms. Which leads me to believe that i have either set up something wrong in nginx, or i am running php wrong.

The second the 32 second request finishes, i get full response back from the server. This is always the case meaning my server seems to only handle one php request at a time. (no php crashes or errors occur)

This is my current server launch file
@ECHO OFF
SET PHP_FCGI_CHILDREN=15
SET PHP_FCGI_MAX_REQUESTS=0
start apps/php/5.6.6/php-cgi.exe -b 127.0.0.1:9000 -c apps/php/5.6.6/php.ini
start apps/mysql/5.6.23/bin/mysqld --standalone --console
start nginx
EXIT

I have attached my php.ini file aswell. Is there something specific i need to be running so nginx can get php to spawn more child process's? could this be an nginx configuration error (every page runs php so no plain files being loaded)? or am i running php incorrectly? I thought it best to ask here as anyone running nginx will most likely be running php as a base aswell

the php i am running is a download of 5.6.6 x64 non thread safe direct from their website (http://windows.php.net/download#php-5.6). If i should be running anything different please let me know as help on this issue would be hugely appreciated.

Also if anyone may know the php or nginx setting i need to change to enable drupal to run its update checks (HTTP request status fails, works in wamp with no issues), that would be great aswell

Regards,
Jamie
Attachments:
open | download - php.ini (72.6 KB)
Re: PHP - only seems to run one instance?
March 05, 2015 05:49PM
Have a look here http://nginx-win.ecsds.eu/
and also the php installer which creates a pool nginx uses (Install_nginx_php_services.zip).

---
nginx for Windows http://nginx-win.ecsds.eu/
Re: PHP - only seems to run one instance?
March 05, 2015 06:52PM
Thank you, i always meant to use that but never could figure put the difference.

reading through the scripts it seems i can use what i have now, but using nginx for windows, changing my start bat file to start a php instance on ports 9001 to 9010, and in the nginx.conf i will only need to set the following, and not both if im reading it correctly

fastcgi_pass myLoadBalancer; # or multiple, see example above

not
fastcgi_pass 127.0.0.1:9000; # single backend process
fastcgi_pass myLoadBalancer; # or multiple, see example above

thanks again in advance,
Jamie
Re: PHP - only seems to run one instance?
March 05, 2015 07:07PM
Can i just say a huge thank you. Changing that also seems to have fixed the issues i was having with drupal instances as well (30 second load with checks now takes 800ms with no errors!!)

i noticed on the website that you also have a download for setting up a ram drive. Is that something you recommend for running nginx?
initially i had it on my SSD, but have just moved it back to a dedicated raid array (normal hdd's)
Re: PHP - only seems to run one instance?
March 06, 2015 05:21AM
See the conf/php-opcache-example.ini example and speed things up near to realtime php execution.

The ramdrive is for use with fast_cgi/proxy_pass where you can deploy a microcache. Examples are in nginx for Windows - documentation 1.0.pdf

In our next release you will find EBLB/IWCP to dynamically manage upstreams such as the php one.

---
nginx for Windows http://nginx-win.ecsds.eu/
Re: PHP - only seems to run one instance?
March 06, 2015 10:02AM
Thanks again, I will look at how to use this more when I get home. I have been reading through the settings and some shown examples and I have a question you may be able to answer. So I have these 2 settings

opcache.revalidate_freq
opcache.validate_timestamps

They both read to do a similar thing except that one can disable checks and the other can't.

Is there a way to set it up so it will always cache unless the file has been updated? I.E. The cache stays, but checks the file last modification time each request. If newer then recache, if the same then just server the file.

I don't know how much checking the timestamp on each request would effect the performance but it shouldn't be a lot as it won't be compiling again unless it's different.

Am I understanding it correctly? If so, how would I set this? As I can often change files on my server a lot, and I need updates as soon as possible from when the changed were made, but I don't want to be recaching the files every time it checks the timestamp.

I hope that makes sense, If not I will try and word it differently. As this could be very helpful as every file on my server (even images) get parsed through a php file, so calling an image goes
User > php > read file > echo content

Rather then
User > content

This is due to the way I handle domains, and so domains, along side permissions and a custom .htaccess rule creator (done using php to save a longer nginx configuration file)

Regards,
Jamie
Re: PHP - only seems to run one instance?
March 06, 2015 11:53AM
The example is how we use it and it works good enough, you would need to test different settings with different circumstances to see what works for you, you may have to switch to xcache which deals much better with frequently changing files then opcache does.

It also depends HOW a file is updated, "newfile->newname->delete old file->rename" is a big nono.
Overwrite the file or truncate and refill it works best with any cache.

---
nginx for Windows http://nginx-win.ecsds.eu/
Re: PHP - only seems to run one instance?
March 06, 2015 12:44PM
Because the server will either be on my editing machine or behind an FTP, it will always be overwritten or edited directly
Re: PHP - only seems to run one instance?
March 06, 2015 01:02PM
So i have just gotten home and enabled opcache with an update every 60 seconds as in the default example. This seems to be working amazing.

My own framework has gone from 12ms to 6ms page load (server is on a hdd and network ping is 6ms)
drupal install had gone down to 64ms from 186ms
wordpress has gone down to 34ms from 176ms
joomla has gone from 670ms to between 170ms - 320ms

all in all, this is a huge difference and i can not thank you enough! i tried editing one of my files and sure enough it updates after the 60 second time.
does it re-cache the file every 60 seconds in the default or does it just check for a change in modification date?
Re: PHP - only seems to run one instance?
March 06, 2015 01:14PM
bigjme Wrote:
-------------------------------------------------------
> does it re-cache the file every 60 seconds in the default or does it
> just check for a change in modification date?

I guess its based on mod_date, use touch to see what it does or check the sources what conditions it uses.

---
nginx for Windows http://nginx-win.ecsds.eu/
Re: PHP - only seems to run one instance?
March 06, 2015 02:44PM
I think for now i will leave it :) i have just simulated 426,000 clicks per hour to my server (i don't have access to many stress test tools) on a stock wordpress site and it handles it, 100% cpu but it handled it, and used around 200mb ram in its entirity.

If i had access to better tools i would test it more but sadly i don't, and as this is just my home server (with no paying users on it atall) it seems to have made an amazing difference.

here is an example of a website using my framework
http://www.cudamining.co.uk/

and here is an example of a wordpress install for you to see the load times
http://wordpress-test.evans-hosting.com/

the caching system seems to delay the php script a while on first load but after that makes a huge difference.
my own framework is managing to handle 1.05million page views per hours, which is amazing at 25 million per day! with the average click time between 7ms and 90ms
Re: PHP - only seems to run one instance?
March 06, 2015 03:00PM
WIth the default nginx.exe or with mine and a few workers active?

Anything asked for the first time will cause a small delay, even nginx has its initializing moments, but once running it blazes.

---
nginx for Windows http://nginx-win.ecsds.eu/
Re: PHP - only seems to run one instance?
March 06, 2015 03:06PM
I am using the nginx you pointed to, the latest version. It seems to be running 9 instances in total, my CPU is a quad core with hyper-threading (intel e3-1230v2, with 8 worker processes running (didn't go above my theoretical core count)

that is with 10 php instances open, set up with the 9001 - 9010 port switch
Re: PHP - only seems to run one instance?
March 06, 2015 04:11PM
Good to know :) but php-cgi (and your OS) also need cpu power, it might perform better with 4 workers.

---
nginx for Windows http://nginx-win.ecsds.eu/
Re: PHP - only seems to run one instance?
March 06, 2015 04:16PM
Right now, unless I hit it with about 1000 page views per second it still runs nowhere near 100% cpu. I plan on upgrading soon to a 16 core 4.5ghz cpu so it should handle it easily :-)
Re: PHP - only seems to run one instance?
March 10, 2015 08:49PM
Can I just ask a final question? Now I have opcache enabled I am getting some server response issues. Every so often I will get load times of around 35 seconds for a page that usually takes 5ms. And some times it will just say no data received. So the server is responding but nothing is being output to the screen.

This seems to occur when opcache does its 60 second cache refresh but it will work find for an hour then do the above issues.

It is loading the same script, on the same machine with no crashes. I don't don't if this is an nginx issue (if I load another page when one is on hold it responds instantly) or if it's a php issue, or even an opcache issue.

This is my last bug to iron out
Re: PHP - only seems to run one instance?
March 11, 2015 04:09AM
Could be a php-cgi which is timing out for some reason, or settings, paste your nginx/php config so we can have a look if there is something which stands out.

---
nginx for Windows http://nginx-win.ecsds.eu/
Re: PHP - only seems to run one instance?
March 11, 2015 04:21AM
php.ini - http://pastebin.com/SPL14Z83
nginx.conf - http://pastebin.com/E2Jnriga

i thought it easier to pastebin it then paste or attach it.

Regards,
Jamie
Re: PHP - only seems to run one instance?
March 11, 2015 05:08AM
As another note, if the script takes around 30 seconds to load, the page loads fine (60 second timeout doesn't trigger)

The issue with the server responding but not getting any data happens instantly like the php server never gave a reply but nginx thinks it has and just serves nothing
Re: PHP - only seems to run one instance?
March 11, 2015 05:52AM
Try these values:
[opcache]
opcache.memory_consumption=512
opcache.interned_strings_buffer=8
opcache.max_accelerated_files=8000
opcache.revalidate_freq=240
opcache.fast_shutdown=1
opcache.enable_cli=0
opcache.enable_file_override=1

Disable this one for nginx,
multi_accept on;

---
nginx for Windows http://nginx-win.ecsds.eu/
Re: PHP - only seems to run one instance?
March 11, 2015 10:15AM
Ok, I will try those settings when I get home. I have seen rumours and some stats that setting revalidate_freq=0 doesn't make much of an effect on load times.

Yes it adds some slight overhead but not a lot by the result graphs I've seen. Also enabling the following line
opcache.validate_timestamps

Overrides the default "reload ever x seconds" and just checks the timestamp for changes instead, if a change then it updates.

I will have a play with some settings tonight but the override files may make a big difference

Thanks,
Jamie
Re: PHP - only seems to run one instance?
March 15, 2015 12:17PM
So i tried these settings and have left it a few days. My phpmyadmin server config which just is like a normal website is showing the very long response time that other pages were as well.

I just get "waiting for ...." responses off the server like it isnt giving a reply but if i load another webpage in a new tab while the other is waiting then i get a reply and the waiting page does as well, almost like nginx is blocking itself.

I am unsure how to trace this error back at all. It doesn't seem to matter how complex the page is either.

Regards,
Jamie
Re: PHP - only seems to run one instance?
March 15, 2015 12:23PM
If nginx is waiting it is waiting for php to return something or until it times out, in that sense php is blocking nginx, you need to study the logfiles, monitor with process explorer and test with "curl -i" to see whats happening along the line. Here its always blazing fast with multiple php applications.
Maybe try xcache for awhile to see if its a php shared memory locking issue.

---
nginx for Windows http://nginx-win.ecsds.eu/
Re: PHP - only seems to run one instance?
March 15, 2015 01:01PM
I started the server and managed to make it lock up in a few minutes. I have attached the error files to see if that may help.

I have looked at xcache and that doesnt seem to support php 5.6.6 atall and actually seems to not have been updated since september 2014 so seems to have been abandoned.

I have also updated my php config with only a 256mb opcache size and have adjusted my nginx config to the one attached. This seems to be working a little better, although i can make all the sites on the server ground to a halt at times, but then reloading one page that is waiting again lets all the others respond again.

I have attached my latest error log aswell, this is with my switching between 6 different website pressing f5 very quickly to force many connections.

Also on a side note, sometimes when i load nginx i get the following error "Assertion failed: ngx_shared_sockets->pid==pid, file src/core/nginx.c, line 376"

After this message shows i have 2 or 3 nginx processes running in windows,they dont respond to requests they are just there until i shut them off. Again this is using nginx for windows 1.7.11.1, not sure if this is a known error or not (may be fixed in 1.7.11.2 which i see is out and may be worth me switching to?)
Attachments:
open | download - error.log (42.3 KB)
open | download - nginx.conf (2.2 KB)
open | download - error-latest.log (69.7 KB)
Re: PHP - only seems to run one instance?
March 15, 2015 01:10PM
Sounds like nginx has not been stopped properly and some old processes are lingering after a restart, make sure it is stopped before restarting, after stopping the service I do a taskkill to make sure nothing is left behind.
I've seen this behavior before and there was something still running while it shouldn't.

---
nginx for Windows http://nginx-win.ecsds.eu/
Re: PHP - only seems to run one instance?
March 15, 2015 01:52PM
Ok that makes sense, i have changed my shutdown script to this (newline is the taskill)

@ECHO OFF
start nginx -s quit
taskkill /f /im nginx.exe
taskkill /f /im php-cgi.exe
start apps/mysql/5.6.23/bin/mysqladmin -u root -p shutdown
EXIT

So that should work. I will leave the settings as they are for now for a few days with the lower opcache size set to see how that works.

Thanks for your help again, you have been a huge help and i hope i can resolve all the issues soon,
Jamie
Re: PHP - only seems to run one instance?
March 17, 2015 04:16PM
Ok so i have been doing some deving on my server today and the issue with retrieving no data or no receiving a response has gotten much worse.

I have disabled opcache entirely to rule that out of the situation. Is there any way to see if it is nginx itself that isn't handling the page requests?
Re: PHP - only seems to run one instance?
March 17, 2015 05:15PM
bigjme Wrote:
-------------------------------------------------------
> I have disabled opcache entirely to rule that out of the situation. Is
> there any way to see if it is nginx itself that isn't handling the
> page requests?

Is the situation the same after removing opcache or haven't you had the issue (yet) after removing?

sendfile off?

Where are the php files located? on the local harddisk or mapped/shared media? for example inside virtualbox using a (vb) shared folder can cause this behaviour.

What does nginx logfiles say? timeout on upstream?

---
nginx for Windows http://nginx-win.ecsds.eu/
Re: PHP - only seems to run one instance?
March 17, 2015 07:02PM
I removed opcache and the issue persisted still so its not an opcache problem.

The server is running on a dedicated physical machine (i'm sitting at it now) and the server is running off a dedicated SSD with nothing else on it but the server. So no shared or mapped drives and no vm's

It happens across 2 different servers, one is my external which uses my own framework proxy, and the other is local only and is just a normal server (on a different port of course) pointing to a folder with only phpmyadmin in it. Again the issue occurs across both of them.

sendfile was enabled a few days ago to see if that helped which it hasnt. (the issue was there while it was off aswell)

Here is a pastebin for my nginx error.log for while i was developing,
http://pastebin.com/TFBCbLjx

some of the "client prematurely closed connection" errors will be because the website sat there and after a fresh was working but as you can see, its a very large error log for not a large amount of time

Regards,
Jamie
Re: PHP - only seems to run one instance?
March 17, 2015 07:20PM
http://forum.nginx.org/read.php?5,245516
http://trac.nginx.org/nginx/ticket/496
http://stackoverflow.com/questions/14167910/nginx-and-mysql-timeout-upstream-timed-out-110-connection-timed-out
http://howtounix.info/howto/110-connection-timed-out-error-in-nginx

---
nginx for Windows http://nginx-win.ecsds.eu/
Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 253
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 500 on July 15, 2024
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready