I am getting error messages when exporting from some Webforms.

Delimited text export:

Warning: fseek() expects parameter 1 to be resource, boolean given in webform_results_batch_eof() (line 1160 of /.../webform/includes/webform.report.inc).

Microsoft Excel export:

Warning: fseek() expects parameter 1 to be resource, boolean given in webform_results_batch_eof() (line 1160 of /.../webform/includes/webform.report.inc).
Warning: fseek() expects parameter 1 to be resource, boolean given in webform_exporter_excel_xlsx->eof() (line 127 of /.../webform/includes/exporters/webform_exporter_excel_xlsx.inc).
Warning: fwrite() expects parameter 1 to be resource, boolean given in webform_exporter_excel_xlsx->eof() (line 128 of /.../webform/includes/exporters/webform_exporter_excel_xlsx.inc).
Warning: unlink(/tmp/webform_gtU8xP): No such file or directory in drupal_unlink() (line 2234 of /.../drupal7/includes/file.inc).

With Excel, the resulting file is invalid.

I had though this might be the same as #2201489: Results export failing when Background Batch module enabled, but that seems not to be the case.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

quicksketch’s picture

So those particular lines are these:

  $handle = @fopen($options['file_name'], 'r+'); // The @ suppresses errors.
  fseek($handle, 0, SEEK_END); // Move pointer to the end of the file.

It seems like fopen() is probably failing at opening the file, so the Boolean FALSE is returned. You might try removing the leading @ from fopen and see if PHP gives you a more useful error message (i.e. access denied or file not found). Is this with a stock installation of Webform? The download is functions correctly in my testing.

quicksketch’s picture

Title: MS Excel export error » MS Excel export error: fseek() expects parameter 1 to be resource
Liam Morland’s picture

I haven't had a chance to investigate it. I did want to open an issue in case others were having this problem.

Liam Morland’s picture

Our Drupal cluster has two web servers. The problem is that Webform puts a file in the Drupal tmp directory, which is specific to each of the two web servers. When the page refreshes through the batch mechanism, if it goes through a different web server from the one it started on, the file is not there, so it errors out. The Drupal tmp directory needs to be shared between the servers.

We could have diagnosed this faster if there was no error suppression on the fopen() call. It seems to me that if the errors are suppressed, Webform should be checking if fopen() succeeded and generating its own errors if it did not. If there is no error checking, then fopen() errors should be exposed. I can write a patch to remove the "@" if you like.

quicksketch’s picture

The problem is that Webform puts a file in the Drupal tmp directory, which is specific to each of the two web servers. When the page refreshes through the batch mechanism, if it goes through a different web server from the one it started on, the file is not there, so it errors out. The Drupal tmp directory needs to be shared between the servers.

Yeah that's a common requirement when working with shared servers.

I'm fine with removing the @. It's been there so long I can't recall what its purpose was. It probably was just to prevent errors from being spewed out all over the place to the end user in the event of a failure, but perhaps that the right thing to do (if you have errors reporting to the screen already).

Liam Morland’s picture

Title: MS Excel export error: fseek() expects parameter 1 to be resource » Remove error suppression from fopen()
Version: 7.x-4.0-beta1 » 7.x-4.x-dev
Status: Active » Needs review
FileSize
2.54 KB

This patch removes the error suppression from fopen().

quicksketch’s picture

Status: Needs review » Reviewed & tested by the community

Let's put this in next pass through the queue.

quicksketch’s picture

Status: Reviewed & tested by the community » Fixed

Committed. Thanks again Liam!

  • Commit 9c7e97c on 7.x-4.x by quicksketch:
    Issue #2202499 by Liam Morland: Remove error suppression from fopen().
    

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

fenstrat’s picture

Version: 7.x-4.x-dev » 8.x-4.x-dev
Assigned: Unassigned » fenstrat
Status: Closed (fixed) » Patch (to be ported)

Needs porting to 8.x-4.x.

fenstrat’s picture

Version: 8.x-4.x-dev » 7.x-4.x-dev
Assigned: fenstrat » Unassigned
Status: Patch (to be ported) » Fixed

Committed and pushed 9c7e97c to 8.x-4.x. Thanks!

  • Commit 3528ce0 on 8.x-4.x authored by Liam Morland, committed by fenstrat:
    Issue #2202499 by Liam Morland: Remove error suppression from fopen().
    

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.