Page 1 of 1
stream_encoding()
Posted: Sun Mar 15, 2009 6:38 pm
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
Re: stream_encoding()
Posted: Sun Mar 15, 2009 6:47 pm
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.
Re: stream_encoding()
Posted: Sun Mar 15, 2009 7:34 pm
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
Re: stream_encoding()
Posted: Sun Mar 15, 2009 7:50 pm
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.
Re: stream_encoding()
Posted: Sun Mar 15, 2009 7:52 pm
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.
Re: stream_encoding()
Posted: Sun Mar 15, 2009 9:48 pm
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
Re: stream_encoding()
Posted: Sun Mar 15, 2009 10:14 pm
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.
Re: stream_encoding()
Posted: Sun Mar 15, 2009 10:56 pm
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).
Re: stream_encoding()
Posted: Mon Mar 16, 2009 1:45 pm
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
Re: stream_encoding()
Posted: Mon Mar 16, 2009 5:16 pm
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.
Re: stream_encoding()
Posted: Mon Mar 16, 2009 6:03 pm
by John Cartwright
Nor mine.