Is there a compression library that has both PHP and JavaScript implementation, such that I can compress/decompress from/to JavaScript/PHP interchangeably?
I know there are different options to compress data with PHP or JavaScript, the problem is that they store their output with different metadata. This means for example, that if some data is compressed into file output.bin using PHP, once I read output.bin using JavaScript (ajax) there is no way I can decompress that stream.
PS: I'm not looking for compression of HTTP requests, I have a bunch of compressed files (throught PHP) which I need to retrieve and decompress using JavaScript.
Thanks
I don't know if something like node.js would fit into your scheme, but it provides fast zlib compression and decompression. php has zlib as well, so that would meet your requirements. If you need a zlib clone written entirely in Javascript, there are several out there that show up in a google search. However I don't know if any are complete or correct.
It's going to be trickier on the Javascript side than the PHP side, but there's lots of discussion and links here.
I'd suggest looking into HTTP-level compression. But if you really want to do this by hand, you could use zlib for example. Both PHP and JS have implementations:
http://www.php.net/manual/en/ref.zlib.php
https://github.com/imaya/zlib.js
Related
I'm trying to make a JSON call library. It has the following features.
be able to customize the header
be able to POST any data to server(including form-encoding (a=1&b=2&c=3) and JSON data chunk)
parse the response and return as a JSON object
I searched in other questions and found that there are only two answers.
use file_get_contents(). This way is pretty simple and easy to use; however, you cannot do anything more than get the content -- you cannot add headers, cannot use POST. But it is usually supported by all servers.
use curl. This way seems powerful and you can do nearly everything with it. The disadvantage is that you have to install libcurl and php-curl support on your server, which means you may not use it on servers that have no curl installed.
So, if I want to develop a common library that can be used on most server, is curl a good choice?
Is there any other ways to do this?
In a short word, I'm looking for a PHP version of urllib2 in python - easy to use, powerful, and reliable.
You have two options: curl and HTTP stream context options. Both can accomplish what you have described; curl might not be installed everywhere, while stream contexts are a core feature and are always available.
Actually, you can also implement your library using sockets, which would be more work but will probably allow you greater control if you need to do weirder things with your requests.
As i know, curl is included in mostly on many server, since it supported from 4.0.2 PHP version natively.
Also there is a native php function header, which customizes your response's headers by simply using like this -> header('location: index.php'), header('cache-control: ok') and so on. You can view Network Functions section on php.net
I want to use compression so that i can speedup my website.Which is the best compression available? Is compression using ob_start("ob_gzhandler"); the best? Does it compress the images embedded.Is there a way to compress those images?
P.S: I don't have access to the server configuration. I only have a FTP account
I would suggest you use the webserver's functions for that. If you use apache, you can check out http://httpd.apache.org/docs/2.0/mod/mod_deflate.html for instance.
Yes, ob_start("ob_gzhandler") is the best you can get if you don't control the server.
The difference between various methods is mainly in efficiency, e.g. some servers or reverse proxies are able to cache compressed data to avoid re-compressing them again. However, gzip is very fast for today's hardware, so even most basic compression in PHP is going to be a net gain.
You should also compress your JS and CSS files, but you shouldn't do that by simply wrapping them in a PHP script, because by default PHP makes files non-cacheable. Any gain from compression will be lost when browsers are forced re-download those files over and over again.
Ideally you should either use a CDN that will compress them for you or ask your host to enable server-level compression for static text files.
No, ob_gzhandler doesn't compress images if you just provide a link in your HTML. Only if you load them into a PHP file as binary data, like with file_get_contents().
I would like to extract a thumbnail from a RAW image file, like Canon's .CR2 or Nikon's .NEF. I've understood that this can somehow be done with ImageMagick, but haven't grasped if it's possible through the PHP wrapper.
Are there any good solutions? Preferably using the built in thumbnail for speed.
Yep, iMagick (the php version of ImageMagick) can handle these extensions: http://www.imagemagick.org/script/formats.php
Here's a great set of tuts that got me going with Imagick. The owner responded to a few of my questions quickly, and despite a bit of a language barrier was able to easily get me through my hurdles
As an aside, I've begun using Gallery to do image admin. No need to worry about thumbnailing, uploading, etc....it's all automatic. Then on the front end I can do jquery magic (getting photos via php query from the gallery database tables) to make it look really good.
Likely, if PHP's imagemagick libraries are to support this, they would be drawing from some functionality exposed through imagemagick's 'identify' command line tool (as the tool would be itself exposing functionality in the imagemagick libraries). Looking at the documentation for this tool, it doesn't look good. If you tried running identify -verbose, theoretically, the thumbnail information would appear in there somewhere, perhaps as an encoded value. Try it yourself: if it does, maybe you could possibly further extract the information returned from identify, either through the imagemagick functions in PHP (though I don't see any past the Exif libraries which only work on JPEG), or by scraping the return of a PHP system call to the identify tool.
Either way, doesn't look likely.
Benjamin Horn has submitted a complete example about reading the requested data and even saving it locally for later use.
Check this out:
https://benjaminhorn.io/code/extracting-thumbnails-from-camera-raw-files-cr2-and-nef-with-php/
Does anybody know a ready-made, reliable way to tell the dimensions (width x height) of a MP4 encoded using the H.264 codec without ffmpeg or similar extensions, in pure PHP?
Thanks for all the answers folks. The bounty is running out and I will not have time to check the offered solutions before it does. I will accept the solution that I feel has the greatest likelihood to work.
getID3 is pure php and extracts an amazing amount of information from media files of all sorts. It will depend on what encoded your file in the first place as to what metadata is available and how reliable it is. getID3 has a nice demo page with lots of different file types. I tried to post more links but as a newbie I only get one.
It sounds like http://code.google.com/p/php-mp4info/ might be your answer. It reads MP4's but it doesn't mention anything about H.264.
also, what OS are you using?
What comes to mind:
mediainfo a huge project with GUI, but also has a CLI
mp4info (part of the seemingly defunct mp4mpeg project) is almost perfect for this
ffmpeg although this is overkill for the task. then again, you very well may need it for other tasks
ffmpeg and php: http://www.lampdeveloper.co.uk/linux/detecting-a-videos-dimensions-using-php-and-ffmpeg.html
php-reader is a full implementation of the ISO 14496 done in pure PHP. You can use this library to read all of the boxes which the mp4 consist of, like the moov atom containing metadata about the file.
Native PHP does not support anything like this, ffmpeg is only one library that come on my mind.
For years, I've been investigating how to create music streams from my computer. I've seen programs, but anything useful I've seen is Windows only (I use a Mac).
Eventually, I got interested in how streams work. Is there any way I could create my own stream, possibly using socket functions in PHP? Is there a PHP library for this?
Take a look at Ampache. It is a Web-based Open Source Audio file manager. It is implemented with MySQL, and PHP. It allows you to view, edit, and play your audio files via the web.
In the end it all boils down to the protocol you'd want to use. Shoutcast IMHO is plain HTTP, so to make your own stream, you just output the streams content.
To make an ogg based webradio work with my Sonos system, I have created a little transcoding wrapper around sox which is is actually written in PHP, so it may be helpful to you to serve as an example.
You'll find it here: http://www.gnegg.ch/ogg2mp3/
If you are after implementing your very own streaming protocol - maybe even UDP based, then, I'm afraid, PHP may not be the right solution for the problem - at least not as long as it has its share of problems when used for long running processes (which 5.3 may bring some help for with its integrated garbage collection)