Archive for the ‘PHP’ Category

Gengo patch for WordPress 2.3.x

January 8th, 2008 by Denis Golovtsov

For whom it’s interesting, you can download patched by me Gengo for WordPress 2.3.x here.

The patch is still be not stable, because code of Gengo is quite complex, therefore it’s not trivial task to fix it, if you are not owner of code. Any way plese post me about any problems there and I will try to fix as far as I will have time for it.

Also I’d like to notice that patch was made without try to keep backward capability with earlier version of WordPress. It was “dirty” hack, purpose of which was only to make it working with my WordPress (v2.3.2). Any way you can post me about any problems.

And finally of course thanks a lot to author of this very well plugin.

The estimate of your PHP skills and some pictures from the Netherlands

December 4th, 2007 by Denis Golovtsov

Nice test which allow to estimate your PHP skills

Nice test, recommend to play in this everybody who knows Russian and PHP little ;)

The Netherlands photos

Other good news came from the Netherlands as the collection of photos with my. Thank you very much for this to Nikos, which finally found his photo camera and sent those photos to me ;)

Update: also available photos shoot by myself during this very nice journey. As you can see some of Nikos photos illustrate the moment when I was shooting something myself, that is fun to see yourself from the side ;)

CodeIgniter memory leak in “Generating Query Results” functions and solution for this

November 22nd, 2007 by Denis Golovtsov

I found that CI framework has memory leak in collection of functions which are described in “Generating Query Results” of CI manual. Those functions need to get access to rows in database result object.

The source code of those function can be found in file: $CI_DIR\system\database\DB_result.php.

Investigate shows that every functions there based on 2 main functions: result_object(), result_array().
The difference between them is type of container which they uses to store values, the first function uses object, second uses associative array. So look at the one will enough to understand the problem and where is source of headache there.

function result_array()
        {
                if (count($this->result_array) > 0)
                {
                        return $this->result_array;
                }

                // In the event that query caching is on the result_id variable
                // will return FALSE since there isn’t a valid SQL resource so
                // we’ll simply return an empty array.
                if ($this->result_id === FALSE OR $this->num_rows() == 0)
                {
                        return array();
                }

                $this->_data_seek(0);         
                while ($row = $this->_fetch_assoc())
                {
                        $this->result_array[] = $row;
                }
               
                return $this->result_array;
        }

Have you guessed it already?
The problem in cycle. In where we walk trough all items, keep every in container array and then return this array. Obviously, if database result has enough many records, as I had in my case, it will work till we will have free memory, then we will get fatal error something like this:

Fatal error: Allowed memory size of 16777216 bytes exhausted (tried to allocate 33 bytes) in /var/www/html/tagnet/system/database/DB_driver.php on line 173

It means that our memory finished. My query had returned approximate 300,000 records, so I suppose it’s not extraordinary case.
Why has authors used such solutions there? I think they would like to use foreach construction very much for a walking in result.

I did not find in google how people solve this problem, may be I was not lucky in my searches. But I found description of the similar problem here. But this problem was fixed by authors of CI.

Bay the way, how I solve this problem?

foreach($result->result_array() as $row) {

}
while ($row = $result->_fetch_assoc()) {

}

Of course it’s not good that I have used “private” member of class CI_DB_result, but I still use CI API for fetching rows and don’t use database dependence functions.

The closing tag of a PHP block.

June 7th, 2007 by Denis Golovtsov

Quote:

Note: The closing tag of a PHP block at the end of a file is optional, and in some cases omitting it is helpful when using include() or require(), so unwanted whitespace will not occur at the end of files, and you will still be able to add headers to the response later. It is also handy if you use output buffering, and would not like to see added unwanted whitespace at the end of the parts generated by the included files.

Source

So the answer is clear, if you are writing class or other library files it’s better not use closing PHP tag in other scrips it’s better to use ;) I had near time ago this kind of problem when we deploy project into new hosting and suddenly warning appeared in one place. Fortunately, I found out the source of problem without much efforts, but as I see know it can be easy to exclude with help preventive actions.

Eventually we have uploadprogrss module for PHP.

May 29th, 2007 by Denis Golovtsov

I found it. It exists already long time, but I didn’t know about it. I’ll check it in work later. I’d like install and configure PHP+Apache+MySQL environment on my localhost for such kinds of toys.

Official site: PECL: uploadprogress

Also today I has short flash back about hacks with iframe+cookies+3rd sites. The key word for this discussion is:

P3P CP=”IDC DSP COR ADM DEVi TAIi PSA PSD IVAi IVDi CONi HIS OUR IND CNT”

There is possible find out much topics based in this key word, later I’d like write short review about this.

phpconf2007

May 26th, 2007 by Denis Golovtsov

So it happened and finished as not sad talking about it, but it was great and very interesting for me. Of course, it was first for me that kind of an arrangement that I cannot give independent overview about or correctly compare it with other or at least with previous conferences.

There are 3 things that I was opened on this conference:

  1. TDD and its teachers pachanga and syfisher;
  2. ngnix (may be somewhen this server can replace apache);
  3. in Russia exists very powerful and serious php (web) underground, there are much good developers and you can get much interesting knowledges while talking with them.