mp3 file stops playing

Re: mp3 file stops playing

by Tim Allen -
Number of replies: 6
Thank you so much Hiroto!  big grin

Yes I am using PHP 5.0.4 and that was exactly the problem.  approve

I am using Moodle 1.4.5 and there is no filelib.php in that version.  So after googling I decided to patch PHP and recompile instead, according to the following diff:

--- php-5.0.4/main/php_streams.h.bug32553	2005-04-25 19:45:27.000000000 +0200
+++ php-5.0.4/main/php_streams.h 2005-04-25 19:46:33.000000000 +0200
@@ -413,7 +413,8 @@
* Uses mmap if the src is a plain file and at offset 0
* To ensure we don't take up too much memory when reading large files, set the default mmap length
* at this many bytes */
-#define PHP_STREAM_COPY_ALL 2000000
+// #define PHP_STREAM_COPY_ALL 2000000
+#define PHP_STREAM_COPY_ALL ((size_t)-1)

BEGIN_EXTERN_C()
PHPAPI size_t _php_stream_copy_to_stream(php_stream *src, php_stream *dest, size_t maxlen STREAMS_DC TSRMLS_DC);
(Source: https://bugzilla.redhat.com/bugzilla/show_bug.cgi?id=155916).

It is all fixed now - I just wish is was easier to find out about this serious bug in PHP.

Thanks again!  smile
In reply to Tim Allen

Re: mp3 file stops playing

by Peter Richardson -
Tim,

I am a newbie at PHP , but seem to have the same problem you did with larger mp3 files.  As a newbie, I could not understand your final post on the subject and since I used Xampp to install PHP, I am unsure how I would recompile.  I am using 5.0.4 and 1.4.5

Can you help?

Thanks.
In reply to Peter Richardson

Re: mp3 file stops playing

by Peter Richardson -
Tim,

More info.  In looking at the Xampp documentation, it looks like it would be easy to go back to php 4.3.11.  Would that solve my problem?  Do you know if it would create others?

Thanks again.

In reply to Peter Richardson

Re: mp3 file stops playing

by Tim Allen -
Hi Peter,

This bug is a problem in PHP version 5.0.4 only, so going back to version 4.3.11 would surely solve the problem, yes!  As far as I know, version 4.3.11 is stable and without bugs, so it shouldn't create other problems for you.

Tim.  smile


In reply to Peter Richardson

Re: mp3 file stops playing

by Robert Brenstein -
I just ran into the same problem: students reported problems downloading large PDF files. Luckily for me, I just read about this PHP bug here big grin

In my installation (OSX 10.3.8, PHP 5.0.4, Moodle 1.4.4+), the file to patch is

/moodle/file.php

And the actual PHP code to replace readfile() is:

  if (filesize($pathname) < 2000000) {
    readfile($pathname);
  } else {
    $fp = fopen($pathname,"rb");
    while (strlen($data = fread($fp,256*1024))) {
      echo $data;
    }
    fclose($fp);
  }


Actually, since I do not filter downloadable files, I needed to replace only the second readfile().
In reply to Peter Richardson

Re: mp3 file stops playing

by Tim Allen -
Hi Peter,

It depends a little on whether you are using XAMPP on Windows, Linux, Mac or other.

In any case, because XAMPP is a bundled package and also because it is not distributed in source code (at least not on the main downloading page), it may be difficult or impossible to fix this problem by patching the source code and then recompiling PHP.

Instead, I suggest you simply use XAMPP with version with PHP 4.3.11, as you suggest in your other post below:

By the following command you can switch "back" to PHP 4.3.x:

/opt/lampp/lampp php4
And with the following command you can switch back to PHP 5.0.x:
/opt/lampp/lampp php5
If you forgot which version of PHP is in use simply use phpinfo() or call this command:
/opt/lampp/lampp phpstatus (from http://www.apachefriends.org/en/xampp-linux.html#374)

You don't even need to reinstall, just switch PHP 4.3.11 on using the commands above. wink

Alternatively, if Moodle is the only PHP software you are running, or if you don't have shell access to your web server, you could change the code within moodle as explained by Peter (and Hiroto) . Do this in moodle/file.php for Moodle 1.4.5 or in lib/filelib.php. I haven't tried this myself but it worked for Hiroto and Peter.

If you need more help, don't hesistate to ask here and I will give more details!
HTH,
Tim. smile

In reply to Peter Richardson

Re: mp3 file stops playing

by Peter Richardson -
Robert and Tim,

Thanks so much for your help.  I tried to follow Robert's advice, but must have done it incorrectly as it did not work.  So I used the xampp command to convert to php 4 and it seems to have worked like a charm (in seconds without a lot of fuss).  I must say, I love those xampp (apachefriends.org) people.

Peter