-1

I am using docker to mount nginx and a PHP-FPM using Phalcon Framework and React as the front end

`upstream fastcgi_backend {
server bfy-%APP_VERSION_UID%_buildify-php-fpm_1:90%FPM_PORT_PREFIX%;
}

server {
# Port 80 will require Nginx to be started with root permissions
# Depending on how you install Nginx to use port 80 you will need
# to start the server with `sudo` ports about 1000 do not require
# root privileges
# listen      80;

listen        80;
server_name $hostname;

##########################
# In production require SSL
# listen 443 ssl default_server;

# ssl on;
# ssl_session_timeout  5m;
# ssl_protocols  SSLv2 SSLv3 TLSv1;
# ssl_ciphers  ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP;
# ssl_prefer_server_ciphers   on;

# These locations depend on where you store your certs
# ssl_certificate        /var/nginx/certs/default.cert;
# ssl_certificate_key    /var/nginx/certs/default.key;
##########################

access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;

# This is the folder that index.php is in
root /var/www/html/public;
index index.php index.html index.htm;

charset utf-8;
client_max_body_size 100M;
fastcgi_read_timeout 1800;

open_file_cache max=100;
output_buffers 5 256k;

set_real_ip_from 172.18.0.9;
real_ip_header X-Real-IP;

# Represents the root of the domain
# http://localhost:8000/[index.php]
location / {
    # Matches URLS `$_GET['_url']`
    try_files $uri $uri/ /index.php?_url=$uri&$args;
}

# When the HTTP request does not match the above
# and the file ends in .php
location ~ [^/]\.php(/|$) {
    # try_files $uri =404;

    # Ubuntu and PHP7.0-fpm in socket mode
    # This path is dependent on the version of PHP install
    fastcgi_pass  fastcgi_backend;


    # Alternatively you use PHP-FPM in TCP mode (Required on Windows)
    # You will need to configure FPM to listen on a standard port
    # https://www.nginx.com/resources/wiki/start/topics/examples/phpfastcgionwindows/
    # fastcgi_pass  127.0.0.1:9000;

    fastcgi_index /index.php;

    include fastcgi_params;
    fastcgi_split_path_info ^(.+?\.php)(/.*)$;
    if (!-f $document_root$fastcgi_script_name) {
        return 404;
    }

    fastcgi_param PATH_INFO       $fastcgi_path_info;
    # fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
    # and set php.ini cgi.fix_pathinfo=0

    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    fastcgi_buffers 64 4k;
    fastcgi_busy_buffers_size 24k;
    fastcgi_buffer_size 16k;
    fastcgi_read_timeout 600s;
    fastcgi_connect_timeout 600s;
}

location ~ /\.ht {
    deny all;
}

location ~* /collections.json$ {
        try_files $uri $uri/ /index.php?_url=$uri&$args;
}

location /products/ {
    location ~* .js$ {
        try_files $uri $uri/ /index.php?_url=$uri&$args;
    }
}

location /collections/ {
    location ~* /products.json$ {
        try_files $uri $uri/ /index.php?_url=$uri&$args;
    }
}

location ~* \.(js|json|css|png|jpg|jpeg|gif|ico)$ {
    expires       max;
    log_not_found off;
    access_log    off;
}

gzip on;
gzip_disable "msie6";

gzip_comp_level 6;
gzip_min_length 1100;
gzip_buffers 16 8k;
gzip_proxied any;
gzip_types
    text/plain
    text/css
    text/js
    text/xml
    text/javascript
    application/javascript
    application/x-javascript
    application/json
    application/xml
    application/xml+rss
    image/svg+xml;
gzip_vary on;
}

and this is the php-fpm config file

[global]
; Pid file
; Note: the default prefix is /var
; Default Value: none
pid = /run/php-fpm.pid

; Error log file
; If it's set to "syslog", log is sent to syslogd instead of being written into a 
local file.
; Note: the default prefix is /var
error_log = /proc/self/fd/2


; syslog_ident is prepended to every message. If you have multiple FPM
; instances running on the same server, you can change the default value
; which must suit common needs.
; Default Value: php-fpm
;syslog.ident = php-fpm

; Log level
; Possible Values: alert, error, warning, notice, debug
; Default Value: notice
log_level = notice

; If this number of child processes exit with SIGSEGV or SIGBUS within the time
; interval set by emergency_restart_interval then FPM will restart. A value
; of '0' means 'Off'.
; Default Value: 0
;emergency_restart_threshold = 0

process_control_timeout = 0

daemonize = no

; Set open file descriptor rlimit for the master process.
; Default Value: system defined value
rlimit_files = 1024

; Set max core size rlimit for the master process.
; Possible Values: 'unlimited' or an integer greater or equal to 0
; Default Value: system defined value
rlimit_core = 0

; Specify the event mechanism FPM will use. The following is available:
; - select     (any POSIX os)
; - poll       (any POSIX os)
; - epoll      (linux >= 2.5.44)
; - kqueue     (FreeBSD >= 4.1, OpenBSD >= 2.9, NetBSD >= 2.0)
; - /dev/poll  (Solaris >= 7)
; - port       (Solaris >= 10)
; Default Value: not set (auto detection)
events.mechanism = epoll


[www]
; if we send this to /proc/self/fd/1, it never appears
access.log = /proc/self/fd/1

user = %FPM_USER%
group = %FPM_GROUP%

;listen.owner = root
;listen.group = root
;listen.mode = 0660
;listen.allowed_clients = 127.0.0.1
listen = 0.0.0.0:%FPM_PORT%

pm = dynamic
pm.max_children = 200
pm.start_servers = 15
pm.min_spare_servers = 15
pm.max_spare_servers = 25
pm.max_requests = 500
pm.process_idle_timeout = 10s

clear_env = no

; Ensure worker stdout and stderr are sent to the main error log.
catch_workers_output = yes

; for debugging 1h
request_terminate_timeout = 3600

I am using it as headless e-commerce using Shopify APIs. The Response from the API is fast but the page takes about 12 seconds to load when I check the requests I see almost all the times is spent waiting for the server Please see screenshot even if I remove the API calls the page takes the same time to load

I want to improve the server response time so that the page does not take 10-12 seconds to load I tried reducing and increasing the pm.max_childern and other pm properties but it did not made a difference. I am using FROM php:7.2-fpm AS phalcon_build.

Is there something wrong with the configuration that is causing the page to load slow?

2
  • 1
    While there's quite a few issues with your config, you haven't asked a question nor provided any information to support a diagnosis of why your site is slow.
    – symcbean
    Commented Jun 6, 2023 at 13:22
  • Questions seeking installation, configuration or diagnostic help must include the desired end state, the specific problem or error, sufficient information about the configuration and environment to reproduce it, and attempted solutions. Questions without a clear problem statement are not useful to other readers and are unlikely to get good answers. See How to Ask
    – djdomi
    Commented Jun 6, 2023 at 16:17

2 Answers 2

0

You should install xhprof, this way you'll see where the time is spent.

Using PECL (https://pecl.php.net/package/xhprof)

pecl install xhprof

And use the xhprof_html and xhprof_lib from this project to show the result: https://github.com/longxinH/xhprof

0

Yes, there's stuff wrong with your config, but your primary issue is arising within the PHP execution (or any persistence layer such as a DB underneath the PHP).

Check for session contention, unnecessary DNS lookups and add instrumentation to record the elapsed time whenever the execution thread leaves PHP (i.e. http calls, database calls, external scripts).

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .