The calls to file_put_contents can be replaced with file_save_data.

CommentFileSizeAuthor
#2 boost_file_save_data.patch1.22 KBalex s

Comments

alex s’s picture

subscribing

alex s’s picture

StatusFileSize
new1.22 KB

Realization of this idea. Solves the problem with race condition.

alex s’s picture

Status: Active » Needs review
robloach’s picture

Status: Needs review » Reviewed & tested by the community

Thanks, Alex. I completely forgot about this issue.

pillarsdotnet’s picture

Status: Reviewed & tested by the community » Needs work

Patch does not work unless variable 'file_directory_path' is equal to '/cache' as per the mod_rewrite ruleset.

Spent a few hours chasing this down, grr!!!

mikeytown2’s picture

@pillarsdotnet
did you come up with a fix for the patch above or did you scrap this patch?

pillarsdotnet’s picture

I worked around it somehow.

Sorry I don't have details, but since then I've stopped using Boost because it has too many bugs that are affecting my customers.

robloach’s picture

If you're using Boost and would like it to be better, then use some of your customer time into fixing it ;-) .

rsvelko’s picture

I am the person here that hunts down red/pink issues and makes them green :) (Its just that I like green so much.)

In short: the patch above is wrong.

The problem here is as #5 says:

"
Patch does not work unless variable 'file_directory_path' is equal to '/cache' as per the mod_rewrite ruleset.
Spent a few hours chasing this down, grr!!!
"

So I guessed that http://api.drupal.org/api/function/file_save_data does sth unintuitive ... and after going through

http://api.drupal.org/api/function/file_move/6 -> http://api.drupal.org/api/function/file_copy/6 -> http://api.drupal.org/api/function/file_create_path/6 -> http://api.drupal.org/api/function/file_directory_path/6

it became clear that this func is meant for drupal managed files that users upload (or js/css caches)... it is not meant for general purpose file saving ...

So with a slight mod of http://api.drupal.org/api/function/file_save_data it should be fine .

But before writing the new func a question:

1. why was it necessary to replace file_put_contents - to remove the php4 compat func ? Or to remedy a race condition - what exactly - when would it come up?

2. is the proper place of boost cache in the sites/default/files ( file_directory_path - settable in core's settings ) - if so we can safely use the file_save_data API func and should document this and provide a notice/move func on update and .... you know make it work

mikeytown2’s picture

Status: Needs work » Closed (won't fix)

Logic for the why is in here: http://api.drupal.org/api/function/file_create_path/6 if $dest doesn't contain the files dir or is a temp dir then it will return false. Only way I see of changing what file_directory_path returns is by changing the database variable. Bad idea. Marking this as won't fix because of that.

@rsvelko
I believe the main reason for this patch is for a possible race condition on a slow box, that all of a sudden gets a huge traffic spike. There will be multiple apache processes trying to write the static html file. Possible solution is flock().

Due to multisite installs, boost needs to stay out of the sites/default/files dir.

mikeytown2’s picture

Found a related issue
#223610: Race condition in cache file creation

This conversation should move there, as I don't see a reasonable way of replacing file_put_contents() with file_save_data().

rsvelko’s picture

Status: Closed (won't fix) » Closed (duplicate)

lets mark this as duplicate of the last one