Well, you did say faster ... not "faster but still using pure PHP".
Stripping it down (things like diagnostics and permissions tests which could slow it down) to emphasise the structure:
function rmtree($directory)
{
if(!is_dir($directory))
{
trigger_error("Unable to delete: not a directory.", E_USER_WARNING);
return;
}
chdir($directory);
rmtree_aux();
chdir('..');
rmdir($directory);
}
function rmtree_aux()
{
foreach(scandir('.') as $entry)
{
if($entry=='.' || $entry=='..') continue;
if(is_file($entry))
{
echo'.....',$entry,"\n";
unlink($entry);
}
else
{
echo $entry,"\n";
chdir($entry);
rmtree_aux();
chdir('..');
rmdir($entry);
}
}
}