Getting 504 gateway timeout in response if the server takes more than 60 secs, process on the server keeps running and complete its execution but on client side getting response 504 gateway timeout of 60 secs so suspecting apache not waiting for PHP to complete its execution and sending gateway timeout response.
Read somewhere that can't increase timeout for apache 2.4.6 it is a known bug for that particular version, so can't try out by increasing the timeout for Apache. My site is running over https and any request that is taking more than 60 sec processing fro php side, getting response gateway timeout 504.
Note: No proxy and no load balancer is there, the server is setup on Amazon EC2 and running (LAMP: Linux CentOS 7, Apache 2.4.6, MySQL 5.7, PHP 5.6)