You are here: Streams and wrappers « PHP Programming Language « IT news, forums, messages
Streams and wrappers

Posted by Julien Biezemans on 06/25/07 15:11

Hi!

Here is another post concerning stream wrappers. I'm trying to implement
a urn: scheme stream wrapper but this does not seem possible with PHP.

Why? Because PHP analyzes URI with the following syntax:

scheme "://" target

Where _scheme_ is what they incorrectly call a "protocol" in the
documentation and _target_ the actual target of the URI.

When dealing with things like http://www..., ftp://ftp..., everything is ok.

But how are we supposed to support things like mailto:user@domain.com,
urn:xmpp:..., h323:host... and other schemes that are NOT followed by
"://" but only ":"?

If you try to register the mailto "protocol" (which is, again, not the
correct term), you will do:

stream_wrapper_register('mailto', 'MyMailToClass');

But this wrapper class will not be used at all by PHP if you try this:

fopen('mailto:user@domain.com', 'w');

Instead you will have to write:

fopen('mailto://user@domain.com', 'w');

Which is wrong (see http://www.rfc-editor.org/rfc/rfc2368.txt).


PHP consider that 'mailto:user@domain.com' falls into the default
(file://) scheme as it does not find the "://" string after the
so-called "protocol".

We may intercept URI's not containing those "://" characters with a
custom file:// stream wrapper. When the wrapper is called by PHP and the
"path" starts with a recognized scheme like "mailto:", it may delegate
the work to the actual mailto: wrapper. But this is just a workaround as
it is supposed to handle resources on the local filesystem only.


I understand that this behavior is probably caused by
fopen('some:file.dat'); being mostly used to open a file that has a
column character in its name and located in the current working
directory (: character is not allowed in file names on windows, I
guess). It simply demonstrates once again a problem that may arise with
the default implicit file:// scheme in URI's.

Anyway, I'm still posting to read your thoughts on this. Maybe someone
will see another solution than the workaround I explained above.

Thank you!

Julien.

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация