Php ftp_* eats memory

Bug #1044430 reported by kaiszy
12
This bug affects 2 people
Affects Status Importance Assigned to Milestone
php5 (Ubuntu)
Confirmed
Undecided
Unassigned

Bug Description

Hi!

Today i write a small "Transport"-Class for my web deployment-System. Its a php-Script "behind" apache2 where i can post json_arrays to and the deployserver than starts to get git-Repository, check files and deploy them by ftp, ftps and so on.

I wonmder about memory usage when in transfer big projects (typo3-Projects for example). I use xdebug to find memory leaks and firgure out that ftp_* Commands in php are the "memory eater".

So i write a small script that only connects to a ftp-server and ftp_put a file 10000 times and then close the connection.

Result: The memory gets lower and lower and also after ftp_close never will be free'd. Only a restart of apache2 helps.

Some Informations:

Description: Ubuntu 12.04 LTS
Release: 12.04

PHP 5.3.10-1ubuntu3.1 with Suhosin-Patch (cli) (built: May 4 2012 02:20:36)
Copyright (c) 1997-2012 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2012 Zend Technologies

Server version: Apache/2.2.22 (Ubuntu)
Server built: Feb 13 2012 01:51:50

[PHP Modules]
apc
bcmath
bz2
calendar
Core
ctype
curl
date
dba
dom
ereg
exif
fileinfo
filter
ftp
gettext
hash
iconv
imagick
json
libxml
mbstring
memcache
mhash
mysql
mysqli
openssl
pcntl
pcre
PDO
pdo_mysql
pdo_sqlite
Phar
posix
readline
Reflection
session
shmop
SimpleXML
soap
sockets
SPL
sqlite3
standard
sysvmsg
sysvsem
sysvshm
tokenizer
wddx
xml
xmlreader
xmlwriter
xsl
zip
zlib

[Zend Modules]

Tags: bot-comment
Revision history for this message
kaiszy (kai-szymanski) wrote :
Revision history for this message
Ubuntu Foundations Team Bug Bot (crichton) wrote :

Thank you for taking the time to report this bug and helping to make Ubuntu better. It seems that your bug report is not filed about a specific source package though, rather it is just filed against Ubuntu in general. It is important that bug reports be filed about source packages so that people interested in the package can find the bugs about it. You can find some hints about determining what package your bug might be about at https://wiki.ubuntu.com/Bugs/FindRightPackage. You might also ask for help in the #ubuntu-bugs irc channel on Freenode.

To change the source package that this bug is filed about visit https://bugs.launchpad.net/ubuntu/+bug/1044430/+editstatus and add the package name in the text box next to the word Package.

[This is an automated message. I apologize if it reached you inappropriately; please just reply to this message indicating so.]

tags: added: bot-comment
kaiszy (kai-szymanski)
affects: ubuntu → php5 (Ubuntu)
Revision history for this message
Clint Byrum (clint-fewbar) wrote :

Hello! I am not able to reproduce this using php5-cli from precise or quantal. If I add checks using memory_get_usage(), I get a delta of 288 bytes, and then actually 0 delta once ftp_close is called.

Can you provide more information on how you used xdebug to determine it was ftp_* causing your memory leaks? Also have you tried using gc_enable();gc_collect_cycles() in your code after doing a lot of operations, to see if the memory is freed?

Marking Incomplete pending response.

Changed in php5 (Ubuntu):
status: New → Incomplete
Revision history for this message
Launchpad Janitor (janitor) wrote :

[Expired for php5 (Ubuntu) because there has been no activity for 60 days.]

Changed in php5 (Ubuntu):
status: Incomplete → Expired
Changed in php5 (Ubuntu):
status: Expired → Confirmed
Revision history for this message
Ryan C. Underwood (nemesis-icequake) wrote :

This is a real bug.

Here is the patch that fixes it.
http://git.php.net/?p=php-src.git;a=commitdiff;h=0863a0d6a0f740874b4ef8dc732a4ec94949470c

Here is the bug I filed in the debian BTS.
https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=752366

Without this patch an attacker can launch a denial of service on the server due to resource exhaustion if he knows of a script to target.

Revision history for this message
Ryan C. Underwood (nemesis-icequake) wrote :

Also, you would not see the leak using memory_get_usage() because the memory is leaked outside of PHP, but due to PHP's mishandling of the connection. So dismissing the bug reporter on this basis was not really fair.

Revision history for this message
Ondřej Surý (ondrej) wrote :

Ryan, I think that Clint was *being fair* since he has requested additional information from the reporter...

> Can you provide more information on how you used xdebug to determine it was ftp_* causing your memory leaks? Also have you tried using gc_enable();gc_collect_cycles() in your code after doing a lot of operations, to see if the memory is freed?

It's hard for maintainers to debug the issue if we are not provided by all the details.

Revision history for this message
kaiszy (kai-szymanski) wrote :

Hi Ondrej,

you are right...and not :) With a "free" in sh you see that the memory usage goes up. Because Clint (he is the expert) says that he don't lose any memory i thought it was a problem on my system and develop a workaround for our deployment software.

But shame on my the i did not send further informations like clint asked for ;)

CU,
  Kai.

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.