Drupal includes xmlrpc.inc for every non-cached page view. However, the functions from the file are only rarely used. Therefore we need a patch that includes the file from the functions that want to use it.

Comments

killes@www.drop.org’s picture

Assigned: Unassigned » killes@www.drop.org
StatusFileSize
new4.64 KB

Here is a patch that moves the include statement to the functiosn where xmlrpc.inc is actually needed. The patch coul dneed some testing as I do not use those modules (ping, bloggerapi) myself.

killes@www.drop.org’s picture

StatusFileSize
new6.38 KB

Patch updated, I had forgotten drupal.module. thanks to crschmidt for spotting this.

Steven’s picture

drupal_xml_parser_create() does not require xmlrpc.inc...

killes@www.drop.org’s picture

StatusFileSize
new6.06 KB

Ok, updated.

dries’s picture

If xmlrpc.php includes xmlrpc.inc, why do we have to include it in blogapi module's functions once more? Also, the inclusion of xmlrpc.inc in drupal.module can probably be avoided by including xmlrpc.inc in cron.php? Am I missing something?

crschmidt’s picture

Not all of the tasks in drupal.module are run with cron.php: for example, the distributed authentication comes in through drupal.module, which requires code from xmlrpc.inc to create the messages it sends out, as far as I can tell.

So, the drupal.module needs it for distributed authentication stuff, not just for pinging servers and so on.

killes@www.drop.org’s picture

StatusFileSize
new2.8 KB

"If xmlrpc.php includes xmlrpc.inc, why do we have to include it in blogapi module's functions once more?"

As I said, I am not that familiar with that part of Drupal, did not investigate under whch circumstances blogapi functions could be called, and wanted to stay on the safe side. If you are sure that blogapi is always called from xmlrpcs.php, then apply the appended version.

dries’s picture

I'm not 100% sure either, I was merely suggesting an alternative. I think the second patch might work tough, in which case it would be preferred for its simplicity. Not? I'll add "Testing Gerhard's blog API patch to my short term TODO list". Hopefully I get to it tonight after work. Thanks Gerhard.

Kjartan’s picture

Good patch, just a few minor comments.

- Use single quotes for constant strings.
- I noticed some indentations that were off the 2 column, looks like the are in the current code though.
- drupal_directory_ping() will only be invoked from xmlrpc.php so there shouldn't be a need to include the file there.

killes@www.drop.org’s picture

StatusFileSize
new2.64 KB

Updated. Don't know to which spaces you are referring. Guess Drupal CVS needs to be code checked again.

killes@www.drop.org’s picture

StatusFileSize
new2.81 KB

Updated again. It appears that parts of the old patch made it into drupal.module, but the include statement was still in common.inc.

TDobes’s picture

+1... I tested the patch with blogapi.module and w.bloggar and it works fine, as far as I can tell. I like any patch that includes less code on each page view.

dries’s picture

Committed to HEAD. Thanks.

walkah’s picture

Assigned: killes@www.drop.org » walkah
StatusFileSize
new2.38 KB

this patch didn't break blogapi.module, it's true. but it _did_ break drupal.module's distributed authentication feature. the problem is that xmlrpc.inc declares some classes, which will not work if the include statement appears inside a function. see the following for more details:

http://us4.php.net/manual/en/language.functions.php (specifically the comment by albaity at php4web dot com)

the attached patch restores the drupal.module functionality (as well as reintroduces the include in common.inc).

I'm afraid that's just the way it has to be, sorry killes ;)

(this patch also fixes a typo in drupal.module where the 'name' array key was not quoted - which may break things under higher error reporting levels).

Anonymous’s picture

Can't you include common.inc from drupal.module if it needs that file? locale.module also includes its locale.inc without punishing the user who doesn't care about its functionality.
Gerhard

dries’s picture

Including the XML-RPC library at the top of those files/modules that need it sounds like a fair alternative.

Steven’s picture

But that doesn't really help unless you have no XML-RPC modules enabled at all...

jonbob’s picture

What is more, I don't think it even fixes the bug.

The problem is that class declarations in PHP4 are not guaranteed to work correctly when made inside a function. This applies to declarations immediately inside a function definition, or in files included from inside a function definition, or even from files included from files included from function definitions. Note that since module files are included from module_load(), this means class definitions or includes of files that have them cannot safely be in modules.

Basically, conditional inclusion of classes is a no-no. To get around this we'd have to rewrite xmlrpc.inc using functions rather than object methods.

dries’s picture

I reverted the patch.

walkah’s picture

ya, but you forgot to put the include_once back in common.inc . :)

killes@www.drop.org’s picture

Can't just somebody step forward and rewrite that class in functions?

dries’s picture

Anonymous’s picture

killes@www.drop.org’s picture

Title: Conditionally include xmlrpc.inc » Rewrite to use procedures and conditionally include xmlrpc.inc

I'd like to keep this open. It is so nicely assigned. ;->

Anonymous’s picture

*grumble*

killes@www.drop.org’s picture

StatusFileSize
new695 bytes

Here is an alternative approach. XML-RPC requests are suppoed to be POST requests, not GET. By jvandyk and myself.

jvandyk’s picture

This patch affects the inclusion of xmlrpc, which is the xmlrpc client, not xmlrpcs, which is the server and subject to the "all XML-RPC requests are POST requests" rule. Thus, it is ineffective.

However, we should consider eliminating the inclusion of xmlrpc.inc at all in common.inc.

This would speed up Drupal at the expense of modules that use XML-RPC calls having to include xmlrpc.inc themselves.

grepping for xmlrpc_ finds occurrences in drupal.module for cross-drupal-site authentication, foaf.module, livejournalmodule, and waypath.module.

jvandyk’s picture

And now that I've revisited JonBob's comments on this, I can see why it's currently the way it is and can't be conditionally included. Blech.

tangent’s picture

It seems that implementing xmlrpc as a (required) module would work around the include issue. I'm working on a xmlrpc.module from scratch, sort of as a Drupal learning exercise, which uses the XML-RPC extension functions instead of the xmlrpc.inc that we're using now and will reduce the code to a few lines instead of the big class that exists now.

Before I get too far into it though, I'm interested if anyone may have thoughts about why a module is not the way to go, or if there is some reason we shouldn't be using the XML-RPC functions.

moshe weitzman’s picture

chx’s picture

Assigned: walkah » chx
Status: Active » Reviewed & tested by the community
StatusFileSize
new4.4 KB

The new library lets this happen. Also, this patch unifies the xmlrpc() and xmlrpc_multicall() calls. Most sites now load 12K less PHP code for almost all page requests.

chx’s picture

StatusFileSize
new4.58 KB

Dries asked for more clear phpdoc. Robert Douglass and I have enhanced it.

chx’s picture

StatusFileSize
new4.69 KB

Steven found that the faster ./ is missing from xmlrpc.php

chx’s picture

StatusFileSize
new2.17 KB

Dries commited this but something went foobar in the latest two patches and now my phpdoc is broken :( only changes are in the comment.

dries’s picture

Status: Reviewed & tested by the community » Fixed

Committed to HEAD.

Anonymous’s picture

Anonymous’s picture

Anonymous’s picture

Anonymous’s picture

Status: Fixed » Closed (fixed)