Long-running PHP process on nginx

I recent had to allow a PHP script to run for several minutes under Nginx (more specifically, as part of a Laravel app on a DigitalOcean server), after encountering the error “504 Gateway Timeout”. First, to tell Nginx to allow the script to run for a longer period of time, I set the FastCGI read timeout to ten minutes in 
/etc/nginx/sites-available/default :

Second, to increase the amount of time that this particular PHP routine could spend running, I increased the execution time limit programmatically before each processing block:

With this configuration, other PHP scripts are still capped at the default timeout value set in 
php.ini, and no individual block of processing is allowed to run away with the full ten-minute time limit.

Adding many-to-many joins in CakePHP with newEntity

To allow CakePHP 3 to add entries to many-to-many join tables when creating or patching entities, the names of the associations must be added to the array of accessible concrete properties on the model.

The documentation does mention this fact eventually, as a note in the “Patching HasMany and BelongsToMany” section, but not as part of the description of how to create new entities. None of the examples in the “Converting BelongsToMany Data” section mention that they will actually fail as written when creating or patching entities.

The solution—adding a 'tags' => true  entry to the $_accessible  property of Articles—is straightforward, but I felt it was far from obvious. Until this point I had never come across any indication that there were situations in which Cake would treat associations as concrete properties.

Laravel 5.1 “intermediate quickstart” notes

I just ran through Laravel’s intermediate quickstart tutorial. On the whole it was rather well put together and worked with as little or as much copying and pasting as you felt like using. Here I’m just recording a few notes for future reference about non-obvious things I encountered.

Error messages for simple typos

One interesting thing to note is that using curly braces instead of round brackets in your blade templates can lead to not-obviously-related error messages. For instance, my first attempt at a template began with

instead of the correct

While obviously this is a simple typo that is entirely my own fault, the resulting error message,

FatalErrorException in fba8cddd62bd85dee11955629f018a61 line 24:
syntax error, unexpected ‘,’

was not particularly enlightening, and I spent rather longer than I would have liked before noticing my error.

Importing models and policies for authorisation

The tutorial seems to leave out two important lines when it comes to authorising the deletion of tasks via policy. Specifically, when the tutorial gets to the point of adding the new policy to app/Providers/AuthServiceProvider.php ,

it fails to mention that this won’t work until the lines

are also added to the file.

Redirecting on login

Finally, if you create your own files from scratch for the tutorial instead of cloning their repo, then registering and logging in will appear to result in an error,

NotFoundHttpException in RouteCollection.php line 161:

This can be surprising at first, and might make you think there actually is an error in your code, but of course it is essentially just a 404 Not Found error—by default you are redirected to /home , which hasn’t been created. One option would of course be to create home view. Another, which is what the Laravel repo does, is to override the redirection destination in app/Http/Controllers/Auth/AuthController.php  and point it at  /tasks instead.

To do so, simply set the  $redirectTo property to the desired path, for example