Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simple class import like Javascript? #10

Closed
Mainmich opened this issue Jan 9, 2013 · 3 comments
Closed

Simple class import like Javascript? #10

Mainmich opened this issue Jan 9, 2013 · 3 comments

Comments

@Mainmich
Copy link

Mainmich commented Jan 9, 2013

For those who can't install module on the server, can we have a "simple" class like the one for Javascript?

@laruence
Copy link
Member

laruence commented Jan 9, 2013

I am afraid that it's a hard work, lots php codes need to be wrote

@tucson-tom
Copy link

I stumbled onto this project. I was wondering the same thing but realized that a few issues will arise: Floating point conversions will be annoying and any PHP-based userland solution will be at least 100 times slower than a native implementation. Performance will suffer because, for whatever reason, PHP has a hard time with parsing strings one character at a time in userland.

However, I can see where the request comes from because it is fairly standard behavior for a PHP developer who makes an extension to also make a userland function/class-based solution that attempts to use the extension but falls back to the userland function/class implementation if the extension is not available using the same names as those found in the extension. This allows applications to use the library and not fail to operate because the extension isn't installed. The PHP core developers do this already through PEAR.

Within PHP, I still think JSON is the better solution. The primary concern of MessagePack's homepage seems to be bloat in JSON. Throwing gzip at JSON is going to be more effective and the compression will be comparable - actually MessagePack will likely fare worse as is frequently seen with various binary serialization formats when they are compressed (the lead byte or bytes tend to cause dictionaries to reset more frequently). As far as binary data goes, Base64 is sufficient for most needs (33% bloat factor) but if a programmer is bundling binary data in serialized storage, they are probably doing it wrong.

PHP also has serialize() and unserialize(), which handles all of PHP's constructs natively. If the app is entirely PHP, there is little reason to not use those built-in and well-maintained functions. You're better off trying to optimize those functions for improved performance than implement an extension.

So, as a storage format, MessagePack isn't really better, and I'd argue worse, than JSON. And for a pure PHP app, possibly worse off than serialize()/unserialize(). Performance is really the only potential significant benefit, which is precisely what the various organizations on the MessagePack homepage are using it for but is not your homepage's focus. Of course, if performance is the only real benefit, this request for a "simple class" in PHP which performs 100 to 1,000 times slower than the extension doesn't actually make any sense. I like the idea of MessagePack for PHP on some level, but PHP already has powerful serialization functionality built-in that has had the bugs hammered out, including several buffer overflow security vulnerabilities.

I don't know how good of a programmer you are, but if my choice is to vet a third-party PHP extension vs. use the built-in stuff that has been vetted repeatedly against a massive test suite, I'm generally choosing the latter. But let's say I would vet your software, I also evaluate how well the sentence structure is of the programmer on public forums. "I am afraid that it's a hard work" says either "English is a second language" or "lazy bum" to me and I approach the project with trepidation knowing that I will have to do a full vetting cycle vs. something a little more casual. Having a well-written PHP function/class would go a long way to validating your status as a programmer to be trusted to run server-level code in the PHP core and would make vetting the extension itself a lot easier for those who have to vet your code before allowing it into real production environments.

I know some of what I said is a bit harsh, but PHP is the 800 lb. web server scripting language gorilla in the room. You can get all the Ruby, Python, and C enthusiasts on board just about any bandwagon and it'll feel good, but PHP has to be targeted differently.

@joeyhub joeyhub mentioned this issue May 18, 2015
@rybakit
Copy link
Contributor

rybakit commented Dec 22, 2015

For the record, I've just released msgpack.php, a pure PHP implementation of the MessagePack serialization format. And the performance is not as bad as one may think.

@m6w6 m6w6 closed this as completed Dec 18, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants