Execute a PHP Script

0

I have a script that imports data from one system to another so it is a system that requires time since it passes almost 300,000 records.

For this I have created a class with PHP using the laravel framework but I get an error 504 when executing the script

  

Gateway Timeout The gateway did not receive a timely response from the   upstream server or application.

     

Apache / 2.4.29 (Ubuntu) Server at local Port 80

That's why what I do is, in the constructor class, set a series of parameters of the php, but with all that I keep getting the error.

The class code is just like this:

class CarsController extends Controller
{

function __construct() {
    ini_set('max_execution_time', 999999);
    ini_set('max_input_time', 999999);
    ini_set('default_socket_timeout', 999999);
    ini_set('memory_limit','4096M');

    parent::__construct();
}


public function readMigration()
{
//Realizar las acciones SQL
}
}

The php configuration uses php7.2-fpm and I have the following

; Default timeout for socket based streams (seconds)
; http://php.net/default-socket-timeout
default_socket_timeout = 60


;;;;;;;;;;;;;;;;;;;
; Resource Limits ;
;;;;;;;;;;;;;;;;;;;

; Maximum execution time of each script, in seconds
; http://php.net/max-execution-time
; Note: This directive is hardcoded to 0 for the CLI SAPI
max_execution_time = 36000

; Maximum amount of time each script may spend parsing request data. It's a good
; idea to limit this time on productions servers in order to eliminate unexpectedly
; long running scripts.
; Note: This directive is hardcoded to -1 for the CLI SAPI
; Default Value: -1 (Unlimited)
; Development Value: 60 (60 seconds)
; Production Value: 60 (60 seconds)
; http://php.net/max-input-time
max_input_time = 36000

; Maximum input variable nesting level
; http://php.net/max-input-nesting-level
;max_input_nesting_level = 64

; How many GET/POST/COOKIE input variables may be accepted
; max_input_vars = 1000

; Maximum amount of memory a script may consume (128MB)
; http://php.net/memory-limit
memory_limit = -1
    
asked by ilernet 25.06.2018 в 10:09
source

1 answer

1

The problem you have is in the FCGI connection that exists between the Apache server and the PHP FPM that puts a maximum waiting time of 30 seconds in the reception of data.

In Ubuntu this file is in /etc/apache2/conf-available/php7.2-fpm.conf or /etc/apache2/conf-available/php7.1-fpm.conf and contains:

# Redirect to local php-fpm if mod_php is not available
<IfModule !mod_php7.c>
<IfModule proxy_fcgi_module>
    # Enable http authorization headers
    <IfModule setenvif_module>
    SetEnvIfNoCase ^Authorization$ "(.+)" HTTP_AUTHORIZATION=$1
    </IfModule>

    <FilesMatch ".+\.ph(ar|p|tml)$">
        SetHandler "proxy:unix:/run/php/php7.1-fpm.sock|fcgi://localhost"
    </FilesMatch>
    <FilesMatch ".+\.phps$">
        # Deny access to raw php sources by default
        # To re-enable it's recommended to enable access to the files
        # only in specific virtual host or directory
        Require all denied
    </FilesMatch>
    # Deny access to files without filename (e.g. '.php')
    <FilesMatch "^\.ph(ar|p|ps|tml)$">
        Require all denied
    </FilesMatch>
</IfModule>
</IfModule>

You must change the line that says:

SetHandler "proxy:unix:/run/php/php7.1-fpm.sock|fcgi://localhost"

By the following (to increase the time to 30 minutes):

SetHandler "proxy:unix:/run/php/php7.1-fpm.sock|fcgi://localhost timeout=1800"

Or configure the following directives instead of the <FilesMatch> block:

<Proxy "unix:/run/php/php7.1-fpm.sock|fcgi://localhost">
   ProxySet timeout=1800
</Proxy>
<FilesMatch ".+\.ph(ar|p|tml)$">
   SetHandler "proxy:unix:/run/php/php7.1-fpm.sock|fcgi://localhost"
</FilesMatch>

I have been able to try this last edition, but I still recommend that you do this type of work through CLI and not through the web server. Increasing the maximum wait time may trigger subsequent problems. As a general rule, a web page should be generated in the shortest possible time.

    
answered by 25.06.2018 / 13:47
source