1

I proceed to explain the problem and scenario a bit complex for my limited knowledge.

initially I thought it was some problem associated with the performance of my scripts and queries, so I created this post on the site in Spanish: LINK

but after researching most of the afternoon; I'm about to attribute it all to a misconfiguration of my dev environments.

I am working with 2 devices server:

  1. Local:

    • Windows 10
    • Laragon Server
  2. Development:

    • Ubuntu 20.04
    • XAMPP

in this case I will focus on local:
I have configured the laragon stack to support virtual hosts and run 2 versions of PHP (7.2 / 7.4) i have follow this 2 guides: Link 1 AND Link 2

my apache configuration:

Define SRVROOT "C:/laragon/bin/apache/httpd-2.4.47-win64-VS16"

ServerRoot "C:/laragon/bin/apache/httpd-2.4.47-win64-VS16"


Listen 80


LoadModule access_compat_module modules/mod_access_compat.so
LoadModule actions_module modules/mod_actions.so
LoadModule alias_module modules/mod_alias.so
LoadModule allowmethods_module modules/mod_allowmethods.so
LoadModule asis_module modules/mod_asis.so
LoadModule auth_basic_module modules/mod_auth_basic.so
LoadModule authn_core_module modules/mod_authn_core.so
LoadModule authn_file_module modules/mod_authn_file.so
LoadModule authz_core_module modules/mod_authz_core.so
LoadModule authz_groupfile_module modules/mod_authz_groupfile.so
LoadModule authz_host_module modules/mod_authz_host.so
LoadModule authz_user_module modules/mod_authz_user.so
LoadModule autoindex_module modules/mod_autoindex.so
LoadModule cgi_module modules/mod_cgi.so
LoadModule dir_module modules/mod_dir.so
LoadModule env_module modules/mod_env.so
LoadModule headers_module modules/mod_headers.so
LoadModule include_module modules/mod_include.so
LoadModule isapi_module modules/mod_isapi.so
LoadModule log_config_module modules/mod_log_config.so
LoadModule mime_module modules/mod_mime.so
LoadModule negotiation_module modules/mod_negotiation.so
LoadModule rewrite_module modules/mod_rewrite.so
LoadModule setenvif_module modules/mod_setenvif.so
LoadModule socache_shmcb_module modules/mod_socache_shmcb.so
LoadModule ssl_module modules/mod_ssl.so
LoadModule version_module modules/mod_version.so

<IfModule unixd_module>
    User daemon
    Group daemon
</IfModule>

ServerAdmin admin@example.com

ServerName Laragon

<Directory />
    AllowOverride none
    Require all denied
</Directory>


DocumentRoot "C:/laragon/www"
<Directory "C:/laragon/www">
    Options Indexes FollowSymLinks Includes ExecCGI
    AllowOverride None
    Require all granted
</Directory>

<IfModule dir_module>
    DirectoryIndex index.html index.php
</IfModule>

<Files ".ht*">
    Require all denied
</Files>

ErrorLog "logs/error.log"

LogLevel error

<IfModule log_config_module>
    
    LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
    LogFormat "%h %l %u %t \"%r\" %>s %b" common

    <IfModule logio_module>
      LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %I %O" combinedio
    </IfModule>

    CustomLog "logs/access.log" common

</IfModule>

<IfModule alias_module>
    
    ScriptAlias /cgi-bin/ "${SRVROOT}/cgi-bin/"

</IfModule>

<IfModule cgid_module>
    #
    # ScriptSock: On threaded servers, designate the path to the UNIX
    # socket used to communicate with the CGI daemon of mod_cgid.
    #
    #Scriptsock cgisock
</IfModule>


<Directory "${SRVROOT}/cgi-bin">
    AllowOverride None
    Options None
    Require all granted
</Directory>

<IfModule headers_module>
    RequestHeader unset Proxy early
</IfModule>

<IfModule mime_module>

    TypesConfig conf/mime.types


    AddType application/x-compress .Z
    AddType application/x-gzip .gz .tgz

</IfModule>



# Configure mod_proxy_html to understand HTML4/XHTML1
<IfModule proxy_html_module>
    Include conf/extra/proxy-html.conf
</IfModule>


<IfModule ssl_module>
    SSLRandomSeed startup builtin
    SSLRandomSeed connect builtin
</IfModule>

AcceptFilter http none
AcceptFilter https none
EnableSendfile Off
EnableMMAP Off

IncludeOptional "C:/laragon/etc/apache2/alias/*.conf"
IncludeOptional "C:/laragon/etc/apache2/sites-enabled/*.conf"
Include "C:/laragon/etc/apache2/httpd-ssl.conf"
Include "C:/laragon/etc/apache2/mod_php.conf"

ScriptAlias /php72 "C:/laragon/bin/php/php72"
Action application/x-httpd-php72-cgi /php72/php-cgi.exe
<Directory "C:/laragon/bin/php/php72">
    AllowOverride None
    Options None
    Require all denied
    <Files "php-cgi.exe">
        Require all granted
    </Files>
</Directory>

the virtual hosts:

<VirtualHost *:80> 
    DocumentRoot "D:/webdev/Local/test1/"
    ServerName test1.me
    ServerAlias *.test1.me
    <Directory "D:/webdev/test1/">
        AllowOverride All
        Require all granted
    </Directory>
    <FilesMatch "\.php$">
        SetHandler application/x-httpd-php72-cgi
    </FilesMatch>
</VirtualHost>

Alias of phpmyadmin

Alias /phpmyadmin "C:/laragon/etc/apps/phpMyAdmin/"
<Directory "C:/laragon/etc/apps/phpMyAdmin/">
    Options Indexes FollowSymLinks MultiViews
    AllowOverride all  
    Require local
</Directory>

MySQL configuration

[client]
#password=your_password
port=3306
socket=/tmp/mysql.sock

[mysqld]
port=3306
socket=/tmp/mysql.sock
key_buffer_size=512M
max_allowed_packet=4096M
table_open_cache=256
sort_buffer_size=32M
read_buffer_size=32M
read_rnd_buffer_size=32M
myisam_sort_buffer_size=128M
thread_cache_size=16

secure-file-priv=""
explicit_defaults_for_timestamp=1
datadir= "C:/laragon/data/mysql"
lower_case_table_names=2
sql_mode=""
wait_timeout=28800
interactive_timeout=28800


[mysqldump]
quick
max_allowed_packet=4096M

PHP configuration for both version (7.2/7.4)

file_uploads = On
upload_max_filesize = 4096M
max_file_uploads = 100
allow_url_fopen = On
memory_limit = 3G
post_max_size = 600M
max_execution_time = 5000
max_input_time = 5000
max_input_vars = 5000
date.timezone= America/Panama
error_reporting = E_ALL
display_errors = on
display_startup_errors = on
html_errors = On
session.gc_maxlifetime = 2592000
session.cache_expire = 2592000

As you can see I am serving php 7.4 by default using apache handler 2.0; I am serving php 7.2 using an alias.

  • phpmyadmin => php 7.4 Apache Handler 2.0
  • test1.me => php 7.2 CGI/FastCGI

error logs of MySQL:

2021-10-02T04:26:59.472441Z 35 [Note] Aborted connection 35 to db: avipac_dbproducts' user: 'root' host: 'localhost' (Got an error writing communication packets)

error logs of Apache:

[Fri Oct 01 23:22:17.806390 2021] [cgi:error] [pid 3808:tid 1108] [client 127.0.0.1:61857] Script timed out before returning headers: php-cgi.exe, referer: http://test1.me/
[Fri Oct 01 23:23:43.661155 2021] [cgi:error] [pid 3808:tid 1108] [client 127.0.0.1:61857] AH01215: PHP Fatal error:  Allowed memory size of 3221225472 bytes exhausted (tried to allocate 20480 bytes) in D:\\webdev\\Local\\test1\\control\\classgeneric\\class.managerdb.php on line 111: C:/laragon/bin/php/php72/php-cgi.exe, referer: http://test1.me/
[Fri Oct 01 23:23:43.676759 2021] [cgi:error] [pid 3808:tid 1108] [client 127.0.0.1:61857] AH01215: PHP Fatal error:  Allowed memory size of 3221225472 bytes exhausted (tried to allocate 65536 bytes) in Unknown on line 0: C:/laragon/bin/php/php72/php-cgi.exe, referer: http://test1.me/
[Fri Oct 01 23:23:43.676759 2021] [cgi:error] [pid 3808:tid 1108] [client 127.0.0.1:61857] AH01215: PHP Fatal error:  Allowed memory size of 3221225472 bytes exhausted (tried to allocate 24576 bytes) in Unknown on line 0: C:/laragon/bin/php/php72/php-cgi.exe, referer: http://test1.me/
[Fri Oct 01 23:24:59.451291 2021] [cgi:error] [pid 3808:tid 1104] [client 127.0.0.1:53918] Script timed out before returning headers: php-cgi.exe, referer: http://test1.me/

I definitely accept that the mysql query is relatively large for a local environment on Windows; but the problem is that the same query is executed by apache handler 2.0 and php 7.4 in less than 1 second ... but in CGI / FastCGI it stops when it reaches the timeout (180 seconds / 3 minutes) ... I have had the delicacy of set the same settings for FastCGI and Apache Handler 2.0 but not concive because one fails and the other does not.

Of course, of course, that's why one of my doubts is that they tell me in my setup what configuration I need to improve FastCGI. It is what I mainly ignore. (where, how and what).

it is possible that someone tell me in my setup what configuration I need to improve FastCGI. It is what I mainly ignore. (where, how and what) I really don't understand why I can't make Fast CGI at least not break and work like Apache does ...

I do not know what is wrong, what I need or how to solve these errors ... I know that CGI / FastCGI is taking a long time and consuming a lot of memory but I don't know why it not work and Apache Handler Work correctly

Or exist any way to proxy Apache Handler 2.0 instead of use php-cgi via FastCGI alias?


Illustrative Images Apache Handler 2.0:

enter image description here

CGI/FastCGI:

enter image description here

enter image description here


UPDATE #1

i find this configuration file: Note: I am assuming that this configuration file is important; but I have no idea of its functionality or what things should I add, remove or modify to make FastCGI behave like Apache Handler 2.0.

    LoadModule fcgid_module "C:/laragon/etc/apache2/modules/mod_fcgid-2.3.10-win64-VS16.so"

<IfModule fcgid_module>
    FcgidInitialEnv PATH "C:/laragon/bin/php/php74;C:/Windows/system32;C:/Windows;C:/Windows/System32/Wbem;"
    FcgidInitialEnv SystemRoot "C:/Windows"
    FcgidInitialEnv SystemDrive "C:"
    FcgidInitialEnv TEMP "C:/Windows/Temp"
    FcgidInitialEnv TMP "C:/Windows/Temp"
    FcgidInitialEnv windir "C:/Windows"

    # 10 hrs: in case you have long running scripts, increase FcgidIOTimeout 
    
    FcgidIOTimeout 36000
    FcgidIdleTimeout 36000
    FcgidProcessLifeTime 36000
    FcgidBusyTimeout 36000
    FcgidConnectTimeout 3600
    FcgidMaxRequestsPerProcess 0
    FcgidMaxProcesses 50
    FcgidMaxRequestLen 81310720
    # Location php.ini:
    # FcgidInitialEnv PHPRC "C:/laragon/bin/php/php74"
    FcgidInitialEnv PHP_FCGI_MAX_REQUESTS 0

    <Files ~ "\.php$>"
        AddHandler fcgid-script .php
        Options +ExecCGI
        FcgidWrapper "C:/laragon/bin/php/php74/php-cgi.exe" .php
    </Files>
</IfModule>
ArcanisGK507
  • 113
  • 5
  • The query you are performing creates a huge result table, and it doesn't fit into the allowed memory limit of your setup. You should fix your query so that it generates only the data you need. – Tero Kilkanen Oct 02 '21 at 06:41
  • I have tried it and it should get 2000 row with 120 columns so heavy is it? is what I need to get. – ArcanisGK507 Oct 02 '21 at 07:06

1 Answers1

1

The errors tells you its PHP (Version 7.2, EoL now, fix that!) that is trying to exceed its allocated memory limit.

If the script was terminated while talking to the database (the mysql logs makes me think so), then maybe one of your database queries (not necessarily the last one!) is returning an unexpectedly large result set that does not fit the memory allowed for the php script?

Check query log, execute the queries manually and see

  • if are appropriate: then you want to allocate more resources OR:
  • if one of them is unnecessarily large: then you want to improve the application querying them or cleanup unnecessary rows to reduce resource usage.

If it is the former, then keep in mind most systems are setup to have separate php configurations for separate deployment options. This may include different memory limits or available extensions. As you have multiple different deployments, the used php.ini file may be different for each of cgi, cli, fpm, apache2-mod, .. - if in doubt, let your script print phpinfo() to confirm the effective configuration.

anx
  • 6,875
  • 4
  • 22
  • 45
  • It seems to me that it is not the right way; I definitely accept that the query is relatively large for a local environment on windows; but the problem is that the same query is executed by apache handler 2.0 and php 7.4 in less than 1 second ... but in CGI / FastCGI it stops when reaching the timeout (180 seconds / 3 minutes) my doubts: where do I modify this time out already confgured the php.ini and does not use it; why CGI / FastCGI takes so long and consumes so much memory, how do I improve this. – ArcanisGK507 Oct 02 '21 at 17:15
  • Of course, of course, that's why one of my doubts is that they tell me in my setup what configuration I need to improve FastCGI. It is what I mainly ignore. (where, how and what) – ArcanisGK507 Oct 02 '21 at 17:58
  • It seems to me that I have not found a complete guide, on the configuration of Fast CGI ... that mentions the points that are affecting me. – ArcanisGK507 Oct 02 '21 at 17:59
  • Hey, thank you very much for your time and your answer. I'll be waiting a little longer to see if I find something that improves my setup. – ArcanisGK507 Oct 02 '21 at 18:00
  • You should edit your question to clarify.. from your comments it sounds like you are trying to identify diagnostic steps to compare two different configuration files, whereas your question reads more like you need a stern reminder that trying to fix issues is not any easier if you keep using unmaintained software version with a large amount of since-fixed bugs. – anx Oct 02 '21 at 18:18
  • A thousand apologies I have updated my post with a little more context about my doubts and what I am really looking for. – ArcanisGK507 Oct 02 '21 at 18:32