PHP - Is 50mb Memory Consumption Normal ?
Hi All, When I put echo memory_get_usage(); at the very beginning of a php file I get 51207808. Is this normal while there is not much processing to do ? This happens even for very small php files that only display html syntax. Thanks! Similar TutorialsHey guys im fairly new to php i cant really keep using that as an excuse anyway im to the point where i am comfortable with procedural php style programming and i have moved on to object orientated and prepared statements etc. Anyways this has no relevance to that sorry. Ok when using $_GET in php say for example i wanted to log a user out i would use ?status=logout or whatever i have started to instead use that use codes like ?abihcofscj=21904jkq i know this looks weird and there is probs no need but does any over sites use this type of behavior or am i just being retarded haha thanks hello i have some normal php functions that i want to put into a oop class. i cant seem to make the right changes to make it work. could some one help please. thanks these are the php functions Code: [Select] <?php function hasChild($parent_id) { $sql = "SELECT COUNT(*) as count FROM category WHERE parent_id = '" . $parent_id . "'"; $qry = mysql_query($sql); $rs = mysql_fetch_array($qry); return $rs['count']; } function CategoryTree($list,$parent,$append) { $list = '<li>'.$parent['name'].'</li>'; if (hasChild($parent['id'])) // check if the id has a child { $append++; $list .= "<ul class='child child".$append."'>"; $sql = "SELECT * FROM category WHERE parent_id = '" . $parent['id'] . "'"; $qry = mysql_query($sql); $child = mysql_fetch_array($qry); do{ $list .= CategoryTree($list,$child,$append); }while($child = mysql_fetch_array($qry)); $list .= "</ul>"; } return $list; } function CategoryList() { $list = ""; $sql = "SELECT * FROM category WHERE (parent_id = 0 OR parent_id IS NULL)"; $qry = mysql_query($sql); $parent = mysql_fetch_array($qry); $mainlist = "<ul class='parent'>"; do{ $mainlist .= CategoryTree($list,$parent,$append = 0); }while($parent = mysql_fetch_array($qry)); $list .= "</ul>"; return $mainlist; } ?> this is the class Code: [Select] <?PHP require_once(LIB_PATH.DS.'database.php'); class Menu extends DatabaseObject { protected static $table_name="menu"; protected static $db_fields = array( 'id', 'parent_id', 'name' ); public $id; public $parent_id; public $name; // "new" is a reserved word so we use "make"(or "build") public static function make( $id, $parent_id, $name) { if(!empty($id)) { $kw = new Menu(); $kw->id = (int)$id; $kw->parent_id = (int)$parent_id; $kw->name = $name; return $kw; }else{ return false; } } //end function make //PUT FUNCTIONS HERE...... function hasChild($parent_id) { $sql = "SELECT COUNT(*) as count FROM category WHERE parent_id = '" . $parent_id . "'"; $qry = mysql_query($sql); $rs = mysql_fetch_array($qry); return $rs['count']; } function CategoryTree($list,$parent,$append) { $list = '<li>'.$parent['name'].'</li>'; if (hasChild($parent['id'])) // check if the id has a child { $append++; $list .= "<ul class='child child".$append."'>"; $sql = "SELECT * FROM category WHERE parent_id = '" . $parent['id'] . "'"; $qry = mysql_query($sql); $child = mysql_fetch_array($qry); do{ $list .= CategoryTree($list,$child,$append); }while($child = mysql_fetch_array($qry)); $list .= "</ul>"; } return $list; } function CategoryList() { $list = ""; $sql = "SELECT * FROM category WHERE (parent_id = 0 OR parent_id IS NULL)"; $qry = mysql_query($sql); $parent = mysql_fetch_array($qry); $mainlist = "<ul class='parent'>"; do{ $mainlist .= CategoryTree($list,$parent,$append = 0); }while($parent = mysql_fetch_array($qry)); $list .= "</ul>"; return $mainlist; } ?> I have a string in php: Quote Sat, 28 Apr 2012 05:09:45 GMT I want to convert it to timestamp Example: 1335594473 i have Created a Session with this code $_SESSION['USER_NAME'] = trim($_POST['username']) How can i access the $_SESSION['USER_NAME'] in other Pages ; and will this code for $var = $_SESSION[USER_NAME] can i get the SESSIOn value in " $var" variable ?? Hello,
Is anybody aware of a statistical function in PHP which returns the inverse of the normal cumulative distribution, given a probability, mean and standard deviation as inputs? Thank you. Hello all, I have a social network site that has users. Each user has a profile and a id. Myself and two other people are admins and are granted access to certain pages via $admin = true. I have recently hashed everyones passwords. I need to allow admins the ability to proxy a user or login as a different user or become another user for moderation purposes. via OOP there is a $auth->id which is the person's id who is logged in or their user id and $prof->id which is another persons id I am looking at. Meaning if I am looking at someones profile, it is their user id. I am trying to figure out a simple page to create where if $admin you can type a desired id in a input box, press enter and you are all of a sudden logged in as that id. Thanks in advance Hi, I am using PHP mail() function to sent message. Following is the code, the message is received in email account, but as attachment, not displayed in the body section as normal message would. Please can you guys help, as why is this message going as attachment, but not being displayed in the body of email. Below is the url which gives preview as to what I mean. http://i56.tinypic.com/29fujxf.jpg Code: [Select] $to = $_POST['to']; $subject = ' web visior'; $customer = stripslashes($_POST['customer']); $email = stripslashes($_POST['email']); $contactinfo = stripslashes($_POST['contactinfo']); $body = stripslashes($_POST['enquiry']); $header = 'From:'.$email.'\r\n'; $header = 'Reply-To:'.$email.'\r\n'; $header = 'X-Mailer: PHP/' . phpversion(); $header = 'Content-type: text/html\r\n'; $message = '<html><body> <table> <tr><td>From:'.$customer.'</td></tr> <tr><td>Email:'.$email.'</td></tr> <tr><td>Contact No'.$contactinfo.'</td></tr> <tr><td style="center"><b>Message:</b></td></tr> <tr><td>'.$body.'</td></tr> </body></html>'; Regards, Abhishek Just how big can i make this ? Im sure it depends on the server hardware and if thats the case then how does one fidn out how big I can make this. I want to max it out. -SB I am in the midst of developing a web application and despite having a decent amount of experience in web development, I never really stopped and gave a ton of thought to memory when it comes to my php scripts. However, with this project I am using zend framework and it is a decent memory hog. So I have some questions... I am monitoring my memory use for a typical call to my site and it appears as though its somewhere around 20MB. This seems like a ton and I am actively looking for ways to decrease it. One thing I noticed is that when I call zend's date class for the first time, my memory usage shoots up 3MB. However it is pretty much untouched for other instances of this class. So if I do Code: [Select] echo(memory_get_usage()); echo('<br />'); $this->last_login=Zend_Date::now(); echo(memory_get_usage()); echo('<br />'); $this->last_active=Zend_Date::now(); echo(memory_get_usage()); echo('<br />'); The result is Quote 9136448 12812408 12814496 So the jump is with that first call. My question is, if two users are accessing the site at the same time, will they both experience that 3MB memory use? Or will the server have that class in memory so it only uses 3MB once? Basically, if a call to the site uses 20MB of memory, will it be 20MB * the number of users. Or will the server have a lot of the information loaded into memory to subsequent calls so multiple users would use up far less memory then the initial? I would assume the latter is the case based on the fact that reusing zend_date doesn't incur a 3MB hit every time. But without being admin of my server and hvaing tons of folks to test at once, its hard to tell. Hey guys i have been making a website where friends can post on each others profiles like facebookish anyways im not sure if this is th ebest way to do it but i have this below its part of the code that pulls all the friends of the member from the database:: $query_friend = mysql_query("SELECT my_id,friend_id FROM site_friends WHERE my_id='$my_id'"); while($row = mysql_fetch_assoc($query_friend)){ $friend_id = $row['friend_id']; } then i pass it into a function blah blah not got that for yet anyway what happens if this person ends up having 100s of friends will this be harsh on the servers memory? or should i not worry to much ? hope someone can help thanks!! I have osTicket installed on a Centos 5 Os with php5.3.3
I upgraded the osTicket from v1.9.1 to 1.9.4
I now get the following mail when I create a ticket by mailing in the support ticket
This is the mail system at host mail.mydomain.com.
I'm sorry to have to inform you that your message could not be delivered to one or more recipients. It's attached below.
For further assistance, please send mail to <postmaster>
If you do so, please include this problem report. You can delete your own text from the attached returned message.
The mail system
<support@mydomain.com>: Command died with status 255: "/usr/bin/php -q
/var/www/html/support/api/pipe.php". Command output: PHP Fatal error:
Allowed memory size of 268435456 bytes exhausted (tried to allocate 76
bytes) in /var/www/html/support/include/class.osticket.php on line 261 PHP
Warning: Unknown: Error occured while closing statement in Unknown on line
0
The osticket guys have pointed out to me that this is a php error, but I never made any changes to the php config
When I increase the memory in php.ini to 512Mb or even 1024Mb the error persists.
Anyone have any ideas of whether the memory is set/can be set somewhere else or overriding what is in php.ini ?
I have this method that puts files into a zip file from an array list, it looks like this: public function zip($files = array(), $maxMB = 2, $flag = ZIP_NEW){ $this->memory_size = $maxMB * 1024 * 1024; $zip_id = $this->zip_id; $this->zip[] = new ZipArchive(); $this->zip_id++; if($flag == ZIP_NEW){ $open = $this->zip[$zip_id]->open("php://temp/maxmemory:$this->memory_size", ZipArchive::CREATE); $files = (array)$files; if(!empty($files)){ foreach($files as $file){ if(is_file($file)){ $this->zip[$zip_id]->addFile($file); } } } $this->zip[$zip_id]->close(); } $this->function_name = __FUNCTION__; return $this; } I then download them like this: public function download($download_data, $download_name, $type = DOWNLOAD_FILE){ header("Pragma: public;"); header("Expires: 0;"); header("Cache-Control: must-revalidate, post-check=0, pre-check=0;"); header("Content-Type: application/force-download;"); header("Content-Type: application/octet-stream;"); header("Content-Type: application/download;"); header("Content-Transfer-Encoding: binary;"); header("Content-Disposition: attachment; filename=$download_name;"); if($type == DOWNLOAD_FILE){ header("Content-Length: ".filesize($download_data).";"); if($download_data == PHP_MEMORY){ $handle = fopen(PHP_MEMORY."/maxmemory:$this->memory_size", 'r+'); echo stream_get_contents($handle); }else{ readfile($download_data); } }elseif($type == DOWNLOAD_STRING){ header("Content-Length: ".mb_strlen($download_data).";"); echo $download_data; } $this->function_name = __FUNCTION__; return $this; } When I run this code: $files = array("file1.php","file2.php"); $live->zip($files)->download(PHP_MEMORY, "download.zip"); It downloads the file, the only problem is, is that when I open the file I get an error saying the file can not be opened. I know when I actually save it to a file instead of in memory it works. So, I am not sure if it isn't working in the download portion or the create file portion, as I have never worked with php://temp before. Any thoughts on why this doesn't work when using php://temp? Hi: How do I set up an input textbox so that it remembers the text a user entered? Code: [Select] <form name="form1" method="post" action="<?=$_SERVER['PHP_SELF']?>" > <input name="myguess" type="text" value=""> <input type="hidden" name="allTheGuesses" value = ""> <input type="submit" value="GUESS"> </form> I can't seem to figure it out I have a 2-D array that holds a table of information that is stored in a $_SESSION array variable. If all the information in the table is correct, then it should be added to a database. If not correct, it will be sent to a page to be modified. There are a total of three pages: AddInformation.php ProcessInformation.php EditInformation.php Table array is created from a form on AddInformation.php. ProcessInformation.php checks for the validity of the information. And EditInformation.php allows you to update the errored information. A $_SESSION array that is Array[5][9] stops at ProcessInformation.php and doesn't bothering using the header('Location: EditInformation.php') that it is supposed to use. The only difference between the start memory usage and the end memory usage is of 5kb. As far as I know there is enough memory on the operating machine. Is there a way to fix this? Edit: I do not have direct access to the server or its terminal. What happens if you do not unset an array before the script is done executing? I am running through thousands of CSV files, parsing data for hundreds of thousands of customers. It works fine for the first 5/6 hours then starts bogging down bad. I run about 5-10 CSVs per execution...I'm wondering if unsetting the arrays in the script would help this or not...I thought they would be unallocated after the script ends. Am I wrong? Hello Guys, I wanted to know what is memory leakage? Where we have to takecare of ? How to avoid this thing? // in this case, $teams_count = 16 for($j = $tournament->teams_count; $j != 1; $j/2) { echo $j; } What I expect: 16 | 8 | 4 | 2 | 1 What I get: memory exhaustion. Code: [Select] PHP Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 128716801 bytes) Is it so late, I'm missing something? Hello everyone, I made this website using CakePHP, and it was working great, but then suddenly it started giving me this error Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 38 bytes) in /cake/libs/model/datasources/dbo/dbo_mysql.php on line 766 Here is the code that contains line number 766 Code: [Select] /** * Fetches the next row from the current result set * * @return unknown */ function fetchResult() { if ($row = mysql_fetch_row($this->results)) { $resultRow = array(); $i = 0; foreach ($row as $index => $field) { list($table, $column) = $this->map[$index]; $resultRow[$table][$column] = $row[$index]; $i++; } return $resultRow; } else { return false; } } /** Hi: Is this the correct way to do a memory form for a checkbox? Code: [Select] <input name="status[]" id="pending" value="<?=$_POST['pending'] ?>" type="checkbox" /> I have stepped into more than one project with a function similar to the following: Code: [Select] <? /** * xml2array() will convert the given XML text to an array in the XML structure. * Link: http://www.bin-co.com/php/scripts/xml2array/ * Arguments : $contents - The XML text * $get_attributes - 1 or 0. If this is 1 the function will get the attributes as well as the tag values - this results in a different array structure in the return value. * $priority - Can be 'tag' or 'attribute'. This will change the way the resulting array sturcture. For 'tag', the tags are given more importance. * Return: The parsed XML in an array form. Use print_r() to see the resulting array structure. * Examples: $array = xml2array(file_get_contents('feed.xml')); * $array = xml2array(file_get_contents('feed.xml', 1, 'attribute')); */ function xml2array($contents, $get_attributes=1, $priority = 'tag') { if(!$contents) return array(); if(!function_exists('xml_parser_create')) { //print "'xml_parser_create()' function not found!"; return array(); } //Get the XML parser of PHP - PHP must have this module for the parser to work $parser = xml_parser_create(''); xml_parser_set_option($parser, XML_OPTION_TARGET_ENCODING, "UTF-8"); # http://minutillo.com/steve/weblog/2004/6/17/php-xml-and-character-encodings-a-tale-of-sadness-rage-and-data-loss xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0); xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1); xml_parse_into_struct($parser, trim($contents), $xml_values); xml_parser_free($parser); if(!$xml_values) return;//Hmm... //Initializations $xml_array = array(); $parents = array(); $opened_tags = array(); $arr = array(); $current = &$xml_array; //Refference //Go through the tags. $repeated_tag_index = array();//Multiple tags with same name will be turned into an array foreach($xml_values as $data) { unset($attributes,$value);//Remove existing values, or there will be trouble //This command will extract these variables into the foreach scope // tag(string), type(string), level(int), attributes(array). extract($data);//We could use the array by itself, but this cooler. $result = array(); $attributes_data = array(); if(isset($value)) { if($priority == 'tag') $result = $value; else $result['value'] = $value; //Put the value in a assoc array if we are in the 'Attribute' mode } //Set the attributes too. if(isset($attributes) and $get_attributes) { foreach($attributes as $attr => $val) { if($priority == 'tag') $attributes_data[$attr] = $val; else $result['attr'][$attr] = $val; //Set all the attributes in a array called 'attr' } } //See tag status and do the needed. if($type == "open") {//The starting of the tag '<tag>' $parent[$level-1] = &$current; if(!is_array($current) or (!in_array($tag, array_keys($current)))) { //Insert New tag $current[$tag] = $result; if($attributes_data) $current[$tag. '_attr'] = $attributes_data; $repeated_tag_index[$tag.'_'.$level] = 1; $current = &$current[$tag]; } else { //There was another element with the same tag name if(isset($current[$tag][0])) {//If there is a 0th element it is already an array $current[$tag][$repeated_tag_index[$tag.'_'.$level]] = $result; $repeated_tag_index[$tag.'_'.$level]++; } else {//This section will make the value an array if multiple tags with the same name appear together $current[$tag] = array($current[$tag],$result);//This will combine the existing item and the new item together to make an array $repeated_tag_index[$tag.'_'.$level] = 2; if(isset($current[$tag.'_attr'])) { //The attribute of the last(0th) tag must be moved as well $current[$tag]['0_attr'] = $current[$tag.'_attr']; unset($current[$tag.'_attr']); } } $last_item_index = $repeated_tag_index[$tag.'_'.$level]-1; $current = &$current[$tag][$last_item_index]; } } elseif($type == "complete") { //Tags that ends in 1 line '<tag />' //See if the key is already taken. if(!isset($current[$tag])) { //New Key $current[$tag] = $result; $repeated_tag_index[$tag.'_'.$level] = 1; if($priority == 'tag' and $attributes_data) $current[$tag. '_attr'] = $attributes_data; } else { //If taken, put all things inside a list(array) if(isset($current[$tag][0]) and is_array($current[$tag])) {//If it is already an array... // ...push the new element into that array. $current[$tag][$repeated_tag_index[$tag.'_'.$level]] = $result; if($priority == 'tag' and $get_attributes and $attributes_data) { $current[$tag][$repeated_tag_index[$tag.'_'.$level] . '_attr'] = $attributes_data; } $repeated_tag_index[$tag.'_'.$level]++; } else { //If it is not an array... $current[$tag] = array($current[$tag],$result); //...Make it an array using using the existing value and the new value $repeated_tag_index[$tag.'_'.$level] = 1; if($priority == 'tag' and $get_attributes) { if(isset($current[$tag.'_attr'])) { //The attribute of the last(0th) tag must be moved as well $current[$tag]['0_attr'] = $current[$tag.'_attr']; unset($current[$tag.'_attr']); } if($attributes_data) { $current[$tag][$repeated_tag_index[$tag.'_'.$level] . '_attr'] = $attributes_data; } } $repeated_tag_index[$tag.'_'.$level]++; //0 and 1 index is already taken } } } elseif($type == 'close') { //End of tag '</tag>' $current = &$parent[$level-1]; } } return($xml_array); } ?> The strange thing is, this function seems to be used a lot, I even started using it. The issue however, is memory. When the xml is anymore than a small size, it causes out of memory errors while trying to use this function. Does anyone have a similar alternative that is better on the memory? |