stream_encoding()

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
oboedrew
Forum Commoner
Posts: 78
Joined: Fri Feb 20, 2009 1:17 pm

stream_encoding()

Post by oboedrew »

The following code is giving me: "Fatal error: Call to undefined function stream_encoding()."

Code: Select all

$fp=fopen('file.txt', 'wb');
flock($fp, LOCK_EX);
stream_encoding($fp, 'utf-8');
fwrite($fp, $something);
flock($fp, LOCK_UN);
fclose($fp);
Anyone know anything about this? The php manual doesn't have much to say about this function. http://us2.php.net/stream_encoding

PHP Version 5.2.6, by the way.

Thanks,
Drew
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: stream_encoding()

Post by Benjamin »

Based on what I read it should be working, but it seems to be in an off-the-beaten path function group. More than likely your version of PHP was compiled with it disabled. You may need to recompile PHP. Best case scenario, you can enable it as an apache module or in php.ini.

Have a look at phpinfo() and see what the compile flags were set at.
oboedrew
Forum Commoner
Posts: 78
Joined: Fri Feb 20, 2009 1:17 pm

Re: stream_encoding()

Post by oboedrew »

Not sure what some of that jargon means, astions. What exactly does it mean to recompile php? This is shared hosting, so I don't know if I can do that. I had a look through phpinfo, and I don't see anything about stream_encoding or compile flags.

Cheers,
Drew
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Re: stream_encoding()

Post by Chris Corbyn »

I bet this function requires the multibyte function library and/or iconv() support. I hate the way some of these PHP functions aren't enabled/disabled based on user-preference but they're enable/disabled based on the libraries found on the system in which PHP is compiled.

I recently wanted to write some code that uses dns_get_record(), which according to the manual exists in PHP 5 +. It doesn't exist on my system however and it's not a compile flag that enables/disables it... it just happens depending upon what the PHP build scripts find on your system. Quite frustrating if you want to develop public domain code that needs to work on all systems.

~oboedrew, compiling PHP means physically downloading the PHP source code (one of the .tar.gz files on php.net) and compiling the source (PHP is written in C). You won't be able to do that on a shared hosting account though so you'll need to contact your host if something is missing from their PHP installation.
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: stream_encoding()

Post by Benjamin »

I was hoping you would answer this Chris. Do you know of an alternative method to accomplish the utf encoding? That function isn't defined on my box either.
oboedrew
Forum Commoner
Posts: 78
Joined: Fri Feb 20, 2009 1:17 pm

Re: stream_encoding()

Post by oboedrew »

So, the code I posted is alright, right? Can I be certain at this point that the function is actually missing from my host's php installation? If so, is this sort of thing common with functions that have only recently been added to php and that are not often used?

Thanks,
Drew
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: stream_encoding()

Post by Benjamin »

oboedrew wrote:So, the code I posted is alright, right? Can I be certain at this point that the function is actually missing from my host's php installation? If so, is this sort of thing common with functions that have only recently been added to php and that are not often used?
Yes the code is fine. Yes the function is missing, but as Chris stated it may require another library that is not installed. It is common for PHP installations to include a standard set of libraries, and for the administrator to add libraries as required. Every PHP installation does not come with every library.
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Re: stream_encoding()

Post by Chris Corbyn »

So if you were to do this manually you need an understanding of UTF-8. PHP is actually extremely crap and working with byte streams and knowing about encodings. I'm in the middle of writing a stack of ByteStream, Charset and CharacterReader classes for handling this, but basically until PHP can distinguish between BYTE, INTEGER and CHAR types it's messy. Even just (efficiently) casting a character such as "a" into its byte value is not part of the language offering in PHP (no, the ord() function doesn't count as efficient, nor as a language feature).
oboedrew
Forum Commoner
Posts: 78
Joined: Fri Feb 20, 2009 1:17 pm

Re: stream_encoding()

Post by oboedrew »

I asked my web host about this. They believe the php manual is mistaken in stating that this function is available in version 5.2.0+, and that this is a function that will be added in version 6. I'm not sure how to confirm this one way or another, except by finding someone who is using this function in php 5. So, has anyone out there actually been able to use the stream_encoding function in php 5?

Cheers,
Drew
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Re: stream_encoding()

Post by Chris Corbyn »

oboedrew wrote:I asked my web host about this. They believe the php manual is mistaken in stating that this function is available in version 5.2.0+, and that this is a function that will be added in version 6. I'm not sure how to confirm this one way or another, except by finding someone who is using this function in php 5. So, has anyone out there actually been able to use the stream_encoding function in php 5?

Cheers,
Drew
Function doesn't exist on my installation neither.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Re: stream_encoding()

Post by John Cartwright »

Nor mine.
Post Reply