Answers.Body: <p>The import do generate a lot of requests indeed, the one you should care about is the POST one (that does the import). The others are mostly cosmetic to update the counter of how many contacts have been processed so far.</p>
  
  <p>What matters for your rewrite isn't where the code is, but what's the url of that post. It depends of your install (check your log or the console on your browser), but it's likely not including the full path (vendor/civicrm/civicrm-core), eg something like:</p>
  
  <pre><code>location ^~ /civicrm/import/contact { ...
  </code></pre>
  
  <p>one trick I use to see if the location nginx rule is the correct one is to put an invalid fastcgi_pass, 50x errors are easier to see than waiting and trying to guess if the timeout worked or not ;)</p>
  
  <p>This being said, if you have a lot of contacts to import, it's probably safer/easier to write a php script that you run from the CLI and that uses civicrm api to create the contacts (you don't have to deal with timeout, you have more memory, easier to do exactly the tests you want and create the data you need the way you want it.... and that's way easier to re-run if something breaks because some input is invalid)</p>
  
  <p>X+</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-10-12T01:09:07.007Z
Answers.Text: Thanks, I have also tried this path, but it continues to timeout. This _is_ the path I see in the Chrome web console, but it doesn't seem to fix the timeout.
Answers.UserDisplayName: johnramsden
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-10-12T01:14:40.823Z
Answers.Text: I added a link to the error message I'm getting in my post. Why would it be matching that path but still using the wrong fastcgi settings? It matches the global value exactly when it times out.
Answers.UserDisplayName: johnramsden
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-10-12T09:19:37.207Z
Answers.Text: first be sure you are using the rewrite rule you want, replace fastcgi_pass unix:/run/php/php7.2-fpm.sock by fastcgi_pass unix:/tmp/for_sure_will_500_and_doesnt_exist.suck and confirm you get a 50x error
Answers.UserDisplayName: Xavier
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-10-17T19:45:49.450Z
Answers.Text: OK, it doesn't seem to be matching no matter what I do. I added some more to the post, any ideas?
Answers.UserDisplayName: johnramsden
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-10-18T07:26:53.970Z
Answers.Text: you'll probably find more experts on an nginx more focussed community (eg stackoverflow)
Answers.UserDisplayName: Xavier
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-10-11T08:09:42.027Z
Answers.LastActivityDate: 2019-10-11T08:09:42.027Z
Answers.UserDisplayName: Xavier
Body: <p>I'm attempting to override the fpm time out from nginx just for the import. We are importing very large files, and it might take up to a couple hours to complete, so I need to set:</p>
  
  <pre><code>fastcgi_send_timeout 0;
  fastcgi_read_timeout 0;
  </code></pre>
  
  <p>I'm having difficulties understanding what exactly happens during the import in which location I should add this override to.</p>
  
  <p>There seems to be a lot happening during the import, ajax, POST requests etc, and I have tried adding this override to just certain paths, all of which didn't fix the problem.</p>
  
  <p>Our installation is at <code>/vendor/civicrm/civicrm-core</code>, and adding the following location block didn't work.</p>
  
  <pre><code>location ^~ /vendor/civicrm/civicrm-core/CRM/Contact/Import {
          try_files $uri /index.php?$query_string;
          location ~ \.php$ {
              include snippets/fastcgi-common.conf;
              fastcgi_send_timeout 0;
              fastcgi_read_timeout 0;
              fastcgi_pass unix:/run/php/php7.2-fpm.sock;
          }
  }
  </code></pre>
  
  <p>I have tried <code>/civicrm/import/contact</code>, but it still times out with:</p>
  
  <pre><code>upstream timed out (110: Connection timed out) while reading response header from upstream, client: ::ffff:REDACTED, server: REDACTED.com, request: "POST /civicrm/import/contact HTTP/2.0", upstream: "fastcgi://unix:/run/php/php7.2-fpm.sock", host: "REDACTED.com", referrer: "https://REDACTED.com/civicrm/import/contact"
  </code></pre>
  
  <hr>
  
  <p>Trying to use an invalid fastcgi socket seems to imply it's not being matched since it doesn't error out:</p>
  
  <pre><code>location ^~ /civicrm/import/contact {
      ## Standard site protection
      try_files $uri /index.php?$query_string;
      location ~ \.php$ {
          include snippets/fastcgi-common.conf;
          fastcgi_send_timeout 0;
          fastcgi_read_timeout 0;
          fastcgi_pass unix:/tmp/for_sure_will_500_and_doesnt_exist.sock;
      }
  }
  
  location ~ \.php$ {
      include snippets/fastcgi-common.conf;
      fastcgi_pass unix:/run/php/php7.2-fpm.sock;
  }
  </code></pre>
  
  <p>The debug log also shows its matching <code>~ \.php$</code>, why would it not match the import path first?</p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2019-10-11T01:35:06.103Z
Comments.Text: Not sure if this is an exact duplicate of this other question but see https://civicrm.stackexchange.com/a/33153/181
Comments.UserDisplayName: Demerit
Tags: <php><nginx>
Title: Override CiviCRM contact import timeout using PHP-fpm and Nginx
ThreadText: # Override CiviCRM contact import timeout using PHP-fpm and Nginx
  
  (Asked by: username_0 on 2019-10-11)
  
  I'm attempting to override the fpm time out from nginx just for the import. We are importing very large files, and it might take up to a couple hours to complete, so I need to set:
  
  ```
  fastcgi_send_timeout 0;
  fastcgi_read_timeout 0;
  
  ```
  
  I'm having difficulties understanding what exactly happens during the import in which location I should add this override to.
  
  There seems to be a lot happening during the import, ajax, POST requests etc, and I have tried adding this override to just certain paths, all of which didn't fix the problem.
  
  Our installation is at `/vendor/civicrm/civicrm-core`, and adding the following location block didn't work.
  
  ```
  location ^~ /vendor/civicrm/civicrm-core/CRM/Contact/Import {
          try_files $uri /index.php?$query_string;
          location ~ \.php$ {
              include snippets/fastcgi-common.conf;
              fastcgi_send_timeout 0;
              fastcgi_read_timeout 0;
              fastcgi_pass unix:/run/php/php7.2-fpm.sock;
          }
  }
  
  ```
  
  I have tried `/civicrm/import/contact`, but it still times out with:
  
  ```
  upstream timed out (110: Connection timed out) while reading response header from upstream, client: ::ffff:REDACTED, server: REDACTED.com, request: "POST /civicrm/import/contact HTTP/2.0", upstream: "fastcgi://unix:/run/php/php7.2-fpm.sock", host: "REDACTED.com", referrer: "https://REDACTED.com/civicrm/import/contact"
  
  ```
  
  ---
  
  Trying to use an invalid fastcgi socket seems to imply it's not being matched since it doesn't error out:
  
  ```
  location ^~ /civicrm/import/contact {
      ## Standard site protection
      try_files $uri /index.php?$query_string;
      location ~ \.php$ {
          include snippets/fastcgi-common.conf;
          fastcgi_send_timeout 0;
          fastcgi_read_timeout 0;
          fastcgi_pass unix:/tmp/for_sure_will_500_and_doesnt_exist.sock;
      }
  }
  
  location ~ \.php$ {
      include snippets/fastcgi-common.conf;
      fastcgi_pass unix:/run/php/php7.2-fpm.sock;
  }
  
  ```
  
  The debug log also shows its matching `~ \.php$`, why would it not match the import path first?
  
  **Tags:** php, nginx
  
  > **Comments:**
  > **username_1**: Not sure if this is an exact duplicate of this other question but see https://civicrm.stackexchange.com/a/33153/181  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_2 on 2019-10-11. Score: 1
  
  The import do generate a lot of requests indeed, the one you should care about is the POST one (that does the import). The others are mostly cosmetic to update the counter of how many contacts have been processed so far.
  
  What matters for your rewrite isn't where the code is, but what's the url of that post. It depends of your install (check your log or the console on your browser), but it's likely not including the full path (vendor/civicrm/civicrm-core), eg something like:
  
  ```
  location ^~ /civicrm/import/contact { ...
  
  ```
  
  one trick I use to see if the location nginx rule is the correct one is to put an invalid fastcgi\_pass, 50x errors are easier to see than waiting and trying to guess if the timeout worked or not ;)
  
  This being said, if you have a lot of contacts to import, it's probably safer/easier to write a php script that you run from the CLI and that uses civicrm api to create the contacts (you don't have to deal with timeout, you have more memory, easier to do exactly the tests you want and create the data you need the way you want it.... and that's way easier to re-run if something breaks because some input is invalid)
  
  X+
  
  > **Comments:**
  > **username_0**: Thanks, I have also tried this path, but it continues to timeout. This _is_ the path I see in the Chrome web console, but it doesn't seem to fix the timeout.  
  > **username_0**: I added a link to the error message I'm getting in my post. Why would it be matching that path but still using the wrong fastcgi settings? It matches the global value exactly when it times out.  
  > **username_2**: first be sure you are using the rewrite rule you want, replace fastcgi_pass unix:/run/php/php7.2-fpm.sock by fastcgi_pass unix:/tmp/for_sure_will_500_and_doesnt_exist.suck and confirm you get a 50x error  
  > **username_0**: OK, it doesn't seem to be matching no matter what I do. I added some more to the post, any ideas?  
  > **username_2**: you'll probably find more experts on an nginx more focussed community (eg stackoverflow)  
  
  ---
  
  