using arrays instead of stdClass

php.internals

Lukas Kahwe Smith

19 years ago
Hi, Hopefully I am not overlooking something here, but I never really appreciated the fact that all my complex types are returned as stdClass instances by default. Of course you can override this with custom classes via the classmap, but I would much prefer simple boring arrays. This has now become particularly relevant to me as APC seems to be less optimized for handling objects and specifically seems to be buggy handling stdClass [1]. @Dmitry: Could we add yet another option to the soap server class to be able to force array's instead of stdClass? regards, Lukas [1] http://pecl.php.net/bugs/bug.php?id=8118

Dmitry Stogov

19 years ago
Hi Lukas, I don't like to increase complexity of ext/soap with additional options. It is already complex enough and simple object <-> array conversion doesn't provide additional abilities. I don't understand how ext/soap related to APC. Thanks. Dmitry.

Lukas Kahwe Smith

19 years ago
Dmitry Stogov wrote:
> I don't like to increase complexity of ext/soap with additional options. > It is already complex enough and simple object <-> array conversion doesn't > provide additional abilities.
Well we have way more functions to "play" with arrays than we have with objects. Considering that we can have arbitrarily complex structures returned from a soap request, its also not a trivial cast. Even if its just a cast, its will cost performance.
> I don't understand how ext/soap related to APC.
Well the problem is that I am trying to cache soap replies in APC. This seems to be buggy but at the very least will require a serialize/unserialize call, which again adds overhead. So obviously its not directly related, though I am sure that a lot of people will try to cache their soap replies in some way or another. regards, Lukas

Dmitry Stogov

19 years ago
> -----Original Message----- > From: Lukas Kahwe Smith [mailto:mls@pooteeweet.org] > Sent: Tuesday, June 05, 2007 4:47 PM > To: Dmitry Stogov > Cc: 'PHP Developers Mailing List' > Subject: Re: [PHP-DEV] RE: using arrays instead of stdClass > > > Dmitry Stogov wrote: > > > I don't like to increase complexity of ext/soap with additional > > options. It is already complex enough and simple object <-> array > > conversion doesn't provide additional abilities. > > Well we have way more functions to "play" with arrays than we > have with > objects. Considering that we can have arbitrarily complex structures > returned from a soap request, its also not a trivial cast. > Even if its > just a cast, its will cost performance. >
I am not able to change API to use arrays instead of objects, because it will break all existent applications. Support for both will increase complexity and decries performance.
> > I don't understand how ext/soap related to APC. > > Well the problem is that I am trying to cache soap replies in > APC. This > seems to be buggy but at the very least will require a > serialize/unserialize call, which again adds overhead.
I understood. In case of specific requests you can split soap reply into simple elements and cache them. For general solution you have to use serialize(). In any case unserialize() is much faster then real soap request. And saving 405% instead of 400% is not so important. Thanks. Dmitry.

Stanislav Malyshev

19 years ago
> Well the problem is that I am trying to cache soap replies in APC. This > seems to be buggy but at the very least will require a > serialize/unserialize call, which again adds overhead.
Wouldn't array require serializing too? Or APC is able to store arrays in unserialized form? Anyway you could use get_object_vars() I guess.
-- Stanislav Malyshev, Zend Products Engineer stas@zend.com http://www.zend.com/

Lukas Kahwe Smith

19 years ago
Stanislav Malyshev wrote:
>> Well the problem is that I am trying to cache soap replies in APC. >> This seems to be buggy but at the very least will require a >> serialize/unserialize call, which again adds overhead. > > Wouldn't array require serializing too? Or APC is able to store arrays > in unserialized form? Anyway you could use get_object_vars() I guess.
I wrote up a blog post with all the options I see with some microbenchmarks: http://pooteeweet.org/blog/721 I would appreciate feedback, since I am unsure of the results. regards, Lukas

Rasmus Lerdorf

19 years ago
Stanislav Malyshev wrote:
>> Well the problem is that I am trying to cache soap replies in APC. >> This seems to be buggy but at the very least will require a >> serialize/unserialize call, which again adds overhead. > > Wouldn't array require serializing too? Or APC is able to store arrays > in unserialized form?
Yes, APC is able to memcpy arrays directly. -Rasmus

Stanislav Malyshev

19 years ago
> Yes, APC is able to memcpy arrays directly.
I wonder how it deals with internal hash pointers - they can't be valid for anything except current run... Or you mean in does memcmp to values?
-- Stanislav Malyshev, Zend Products Engineer stas@zend.com http://www.zend.com/