Jump to content

Recommended Posts

I recently started working on a Web application that has been written in PHP. It is using the single threaded version of PHP. It runs very slowly when it has a large user base. I have spent some time trying to debug it and speed it up, and have run into a roadblock. The server code executes in 4-5 seconds, and the payload to the client is relatively small. The process php-cgi.exe *32 (CGI /Fast CGI), however, is using lots of memory, and although the header is returned to the client fairly quickly, this process runs for a long time (sometimes for more than 10 minutes). Based on debug info, all of the pages have finished processing. I have not been able to determine the reason for the slowness. My guess is that php is running through the memory cleanup algorithms, and that they are inneficient for large amounts of data.

Has anyone experienced anything like this, or have a workaround?

 

I am currently working to solve the problem from two angles. The first is to try and see if there is a way to help clean memory, but so far I have been unsuccessful.

 

The second is to reduce the data in memory (used by php-cgi.exe) This has also been unsuccessful. There is a function that seems to be using an extraordinary amount of memory to load only a few strings into an array.

 

Here is the code that is called

 

function ado_fetch_array($rs, $result_type, $row_number = -1) {

global $ADO_NUM, $ADO_ASSOC, $ADO_BOTH;

if ($row_number > -1) // Defined in adoint.h - adBookmarkFirst = 1

$rs->Move($row_number, 1);

 

if($rs->EOF) {

return false;

}

 

$ToReturn = array();

 

for($x = 0; $x < ado_num_fields($rs); $x++) {

//200 varchar

//201 text

//202 nvarchar

//203 ntext

//11 bit

//205 image

//135 datetime

 

$value = null;

if ($rs->Fields[$x]->Type == 205) {

//this case is not currently called

}

} else if (in_array($rs->Fields[$x]->Type, array(200,201,202,203))) {

$value = (string) $rs->Fields[$x]->Value;

            } else if ($rs->Fields[$x]->Type == 11) {

$value = (bool) $rs->Fields[$x]->Value;

} else if ($rs->Fields[$x]->Type == 135) {

$value = (string) $rs->Fields[$x]->Value;

//if no time given then add time

if ($value != false && stripos($value,"AM") === false && stripos($value,"PM") === false) {

$value .= " 12:00:00 AM";

}

//WHY? $value = DBUnixTimeStamp($value);

} else {

$value = $rs->Fields[$x]->Value;

}

 

if($result_type == $ADO_NUM || $result_type == $ADO_BOTH) {

$ToReturn[$x] = $value;

}

 

if($result_type == $ADO_ASSOC || $result_type == $ADO_BOTH) {

$ToReturn[(string) $rs->Fields[$x]->Name] = $value;

}

}

$rs->MoveNext();

return $ToReturn;

}

 

here is an example of the data put into the strings (along with about 50 empty strings)

 

9625

Teresa

Kammer

92eb35c4ce8f9a6a43c5a09fb4ad9ab1

92eb35c4ce8f9a6a43c5a09fb4ad9ab1

1

5426

1/8/2007 9:44:52 PM

1544

Hotel Sales

1

1531

Belterra

3

 

This is occupying about 60,000 bytes in memory, which is totally inexplicable to me.

 

Thanks in advance for any help on the problem

Link to comment
https://forums.phpfreaks.com/topic/52065-php-execution-on-fast-cgi-running-slowly/
Share on other sites

What SQL queries are being passed to the function?  That is what will determine the amount of memory it takes up.  If you do a "SELECT * FROM table_name" and that table contains 1000 rows, even if you only use 10 of them, all 1000 are going to be loaded into memory.

I found a function memory_get_usage() for windows and it appears that the entire process of executing the query and bringing back the results occurs quickly and does not consume all the memory. The queries definitely need refining because they bring back too much, but the 60,000 bytes is used only in extracting the data from the record set. The code loops through each user in the record set, and each loop adds about 60,000 bytes to total memory usage. I put a sleep in the code, and compared the memory_get_usage function to the reported usage from task manager, and it the memory usage is tied to looping through the record set and building the objects - the total memory usage jumps from around 20,000 k after query is executed to about 120,000 k after the objects are created.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.