Speed Up Your Wordpress With Very Little Effort

SitePoint Memebers,
I found that the ending “?>” in 3, probably four files is missing:
wp-cron.php. wp-config.php, wp-config-sample.php, and probably wp-links-opml.php, for wordpress 2.9.

I need help on the last one (wp-links-opml.php).

At the end of this php file you’ll see there’s no “?>” Shouldn’t there be? Also, while there’s just as many “{” as “}”, the last “}” in the whole file doesn’t make sense see

"<?php

}
?>"

almost at the bottom of the file. How can you have a closing bracket as the first and only bracket inside <?php …?> ?

If there’s an error please tell me how to fix it.

Here’s the code:

<?php

if (empty($wp)) {
require_once(‘./wp-load.php’);
wp();
}

header(‘Content-Type: text/xml; charset=’ . get_option(‘blog_charset’), true);
$link_cat = $_GET[‘link_cat’];
if ((empty ($link_cat)) || ($link_cat == ‘all’) || ($link_cat == ‘0’)) {
$link_cat = ‘’;
} else { // be safe
$link_cat = ‘’ . urldecode($link_cat) . ‘’;
$link_cat = intval($link_cat);
}
?><?php echo ‘<?xml version=“1.0”?’.">
"; ?>
<?php the_generator( ‘comment’ ); ?>
<opml version=“1.0”>
<head>
<title>Links for <?php echo esc_attr(get_bloginfo(‘name’, ‘display’).$cat_name); ?></title>
<dateCreated><?php echo gmdate(“D, d M Y H:i:s”); ?> GMT</dateCreated>
</head>
<body>
<?php

if (empty ($link_cat))
$cats = get_categories(“type=link&hierarchical=0”);
else
$cats = get_categories(‘type=link&hierarchical=0&include=’.$link_cat);

foreach ((array) $cats as $cat) {
$catname = apply_filters(‘link_category’, $cat->name);

?>
<outline type=“category” title=“<?php echo esc_attr($catname); ?>”>
<?php

$bookmarks = get_bookmarks("category={$cat-&gt;term_id}");
foreach ((array) $bookmarks as $bookmark) {
	$title = esc_attr(apply_filters('link_title', $bookmark-&gt;link_name));

?>
<outline text=“<?php echo $title; ?>” type=“link” xmlUrl=“<?php echo esc_attr($bookmark->link_rss); ?>” htmlUrl=“<?php echo esc_attr($bookmark->link_url); ?>” updated=“<?php if (‘0000-00-00 00:00:00’ != $bookmark->link_updated) echo $bookmark->link_updated; ?>” />
<?php

}

?>
</outline>
<?php

}
?>
</body>
</opml>

Thanks,

Linda

I think if you see the well formatted codes as follows then you will understand what are needed and what are not needed.


<?php
if (empty($wp)) {
	require_once('./wp-load.php');
	wp();
}
header('Content-Type: text/xml; charset=' . get_option('blog_charset'), true);
$link_cat = $_GET['link_cat'];
if ((empty ($link_cat)) || ($link_cat == 'all') || ($link_cat == '0')) {
	$link_cat = '';
} else { // be safe
	$link_cat = '' . urldecode($link_cat) . '';
	$link_cat = intval($link_cat);
}
?>
<?php echo '<?xml version="1.0"?'.">\
"; ?>
<?php the_generator( 'comment' ); ?>
<opml version="1.0">
<head>
	<title>Links for <?php echo esc_attr(get_bloginfo('name', 'display').$cat_name); ?></title>
	<dateCreated><?php echo gmdate("D, d M Y H:i:s"); ?> GMT</dateCreated>
</head>
<body>
<?php
if (empty ($link_cat))
	$cats = get_categories("type=link&hierarchical=0");
else
	$cats = get_categories('type=link&hierarchical=0&include='.$link_cat);

foreach ((array) $cats as $cat) {
	$catname = apply_filters('link_category', $cat->name);
	?>
	<outline type="category" title="<?php echo esc_attr($catname); ?>">
	<?php
	
	$bookmarks = get_bookmarks("category={$cat->term_id}");
	foreach ((array) $bookmarks as $bookmark) {
		$title = esc_attr(apply_filters('link_title', $bookmark->link_name));
		?>
		<outline text="<?php echo $title; ?>" type="link" xmlUrl="<?php echo esc_attr($bookmark->link_rss); ?>" htmlUrl="<?php echo esc_attr($bookmark->link_url); ?>" updated="<?php if ('0000-00-00 00:00:00' != $bookmark->link_updated) echo $bookmark->link_updated; ?>" />
		<?php
	}
	?>
	</outline>
	<?php
}
?>
</body>
</opml>

Not having the closing ?> at the end of file is done on purpose. This is a small trick, actually designed to prevent possible parse errors. Many libraries do that, this is not really a bug, you can even think of it as an optimization technique.
You can google for the answer to what exactly it does and why do this.

I did sort out one non problem; that code is not one large nest but two separate nests, the second part does not start with php. I can tell you with great success that for those interested in speeding up their sites, missing code slows your site considerably. I stil can’t figure the answer to this question: "At the end of this php file you’ll see there’s no “?>” Shouldn’t there be? Also, while there’s just as many “{” as “}”, the last “}” in the whole file doesn’t make sense see
"<?php

}
?>"

Here’s the code in more detail:

<?php if (empty($wp)) {require_once(‘./wp-load.php’);wp();}
header(‘Content-Type: text/xml; charset=’ . get_option(‘blog_charset’), true);
$link_cat = $_GET[‘link_cat’];
if ((empty ($link_cat)) || ($link_cat == ‘all’) || ($link_cat == ‘0’)) {$link_cat = ‘’;} else { // be safe
$link_cat = ‘’ . urldecode($link_cat) . ‘’;
$link_cat = intval($link_cat);}
?> ---------------------php comleted at this point

<?php echo ‘<?xml version=“1.0”?’.">
"; ?> -----------------php completed
<?php the_generator( ‘comment’ ); ?> --------------php completed

____________________________Start opml
<opml version=“1.0”>
<head>
<title>Links for <?php echo esc_attr(get_bloginfo(‘name’, ‘display’).$cat_name); ?></title>
<dateCreated><?php echo gmdate(“D, d M Y H:i:s”); ?> GMT</dateCreated>
</head>
<body>
[COLOR=“Cyan”]
[/COLOR]<?php
if (empty ($link_cat))
$cats = get_categories(“type=link&hierarchical=0”);
else
$cats = get_categories(‘type=link&hierarchical=0&include=’.$link_cat);

foreach ((array) $cats as $cat) {
$catname = apply_filters(‘link_category’, $cat->name);

__ ?>
[COLOR=“DarkGreen”]--------------------Start Outline
<outline type=“category” title=“<?php echo esc_attr($catname); ?>”>
__<?php
$bookmarks = get_bookmarks(“category={$cat->term_id}”);
foreach ((array) $bookmarks as $bookmark) {
$title = esc_attr(apply_filters(‘link_title’, $bookmark->link_name));
__?>
<outline text=“<?php echo $title; ?>” type=“link” xmlUrl=“<?php echo esc_attr($bookmark->link_rss); ?>” htmlUrl=“<?php echo esc_attr($bookmark->link_url); ?>” updated=“<?php if (‘0000-00-00 00:00:00’ != $bookmark->link_updated) echo $bookmark->link_updated; ?>” />

<?php } ?>
</outline> ------------------------------Outline Comleted[/COLOR]

<?php
}
?>

</body>
</opml>

From my experience tasks are either nested or separate so that would mean “outline” is nested inside the hot pink (“magenta”) bracket above and below “outline”, which leads me to believe the cyan colored php code below should be removed. What purpose does the cyan colored php code below serve? Any idea?

Look at <?php } ?> just before </outline>. That doesn’t make any sense either.

<?php
}[/COLOR]
?>

Thanks,

Linda

The ?> is only needed if there is HTML following.

Including ?> at the end of a file to be included means that there could be a space after the > and that could cause all sorts of problems if the file is included earlier than where the last header is written as that space would be sent to the browser and would prevent any subsequent headers being able to be processed. The only way to be sure there is no space at the end of any PHP file is to leave off the ?>

Felgall,
I didn’t quite undestand what you were saying, but in reference to,“a space after the > and that could cause all sorts of problems if…”

I just reloaded my website and these wordpress 2.9.1 wp-files had a blank line after the last line containing the closing ?> and I removed the blank line after reading your post.
wp-settings
wp-mail
wp-login
wp-load
wp-comments-post
wp-app
(and xmlrpc.php)

Not in line with what you were saying, these wp files had no closing ?> so I put one in.
wp-cron
wp-config
wp-config-sample

I think my site runs much faster after making the changes.

Thanks,

Linda

Good work Lindaro,

Now, let know the Wordpress Team about your optimizations, they are going to be ashamed they never hit upon that idea, I think the overall speed is going to increase by about 20%, as missing closing tag causes php hang often, in some cases the php parser is so silly that it reads the php file for 2nd and 3rd time hoping it finds that missing tag.

Good job.


btw, am I the only one having the spam filter disabled so I can see all replies in this topic?

lol

OT I’ve set my spam filter up so I can only see my posts.

BooBoo,
Thanks for your support. Here’s another tweak I use. I changed the css style page filename to aa.css and moved it to the root and made sure I made I changed the file reference in the “rel” line in header.php. Also changed the background image filename to a.jpg and then put this in the aa.css body{background:url(/a.jpg) …}. Keeping the most used files in the root and first in line in the root and referenced from the style page if possible helps too.

Linda