This is a handy little function I’ve used a few times to calculate the aspect ratio of an image or video. Simply give it the width and height and it’ll give you the aspect ratio.
A while ago now (back in February!) I did a talk about writing an extension using Zephir to interact with the RaspberryPi’s GPIO. The extension itself wraps around the wiringPi library and it makes it really easy to write PHP scripts that send output and gather input from the GPIO.
Here are the slides (use left/right arrow keys to navigate):
Just a quick note to say that my thumbnail and VTT creator for JW Player, a script to help extract thumbnails from a video and present them in JW Player a a toolbar preview, has now got the ability to be included in your project via composer. Just use:
composer require amnuts/jwplayer-thumbnail-preview-generator
If you want, you can also browse for it on Packagist.
I’ve pushed a few changes to phpiwire can now use the PWM functions in wiringPi. You can use either the hardware PWM pins or any of the GPIOs by using software PWM. A couple new examples of how to do this have also been added to the repository.
With software PWM comes the requirement to include pthreads, so that’s also linked when you compile the zephir extension.
I’d recommend you do a full clean first before compiling with:
zephir fullclean zephir install
So it’s been a while since my lightening talk on Zephir and I realized I hadn’t really done anything to try to learn it a little more in-depth. Coincidentally, I was recently going through a drawer and realized that one of my Raspberry Pi’s was in there just begging to be put to some use (seriously, I could practically hear it weep). So I thought that the only thing to do was to attempt to write an extension using Zephir so that I could control the GPIO via PHP. I mean, isn’t it obvious? Continue reading Phpiwire: a PHP extension (written using Zephir) for controlling the Raspberry Pi GPIO
I’ve just pushed to github a big overhaul of the opcache gui script. It comes with a sweeping set of changes which also includes using react.js to power some of the interface to really enhance the real-time updates. (OK, it was really just an excuse for me to learn a little about react.js but I think it was worth it!)
I’ve also put the opcache gui and the php error log gui up on packagist – my first packages on there! Check ’em out:
JWPlayer is a fantastic video player for the web. One of the great features it provides is the ability to show thumbnail previews of the video as you slide along the toolbar timeline, much the same way that YouTube and the like allow.
Generating the thumbnail images is not quite so easy unless you have ffmpeg installed and know a bit about the command line options. I got a little frustrated myself having to come up the with the command line magic whenever I needed it, and so the JW Player thumbnail preview generator was born!
It’s a simple command line tool, written in PHP, that allows you to whip up the thumbnails and generate the required VTT file with a command as simple as:
php thumbnails.php -i "/input/video.mp4"
OK, so you still need to have ffmpeg installed on your machine – not much I can do about that one, sorry! – but at least generating the files is now much easier!
You can generate the individual thumbnails or have them coalesced into sprite sheet, and generate a random poster image. Full instructions are on my GitHub account; so go, fork, improve, and feel free to give any feedback.
Recently at work I found myself trawling through the PHP error log file and found that all the lines of text were starting to blur after a while. Thinking there had to be a better way over viewing the log file, and following on from my single-file opcache viewer gui, I decided to knock out something for viewing the error log file as well.
With this single-file error log gui it will only show the error once and then tell you how many times it appears in the log. It will allow you to narrow down your search of errors by being able to hide the different types or sort in different ways, and it will also allow you to search results based on particular file paths.
I’ve pushed the code up to my GitHub account, so please feel free to fork and improve and/or give feedback.
So let’s start by looking at the code and then break it down a little more.
I’ve just started to use Zend OPcache in place of APC in a few places and so far it’s great!
Because documentation seems a little scarce right now, I’ve decided to jot down the methods available (mainly so I don’t forget).
Should be pretty obvious given the name – resets the opcache
This will return an array with three indices, one for the directives that have been set, one for version information and one for any blacklisted paths. For example:
Array ( [directives] => Array ( [opcache.enable] => 1 [opcache.enable_cli] => 1 [opcache.use_cwd] => 1 [opcache.validate_timestamps] => 1 [opcache.inherited_hack] => 1 [opcache.dups_fix] => [opcache.revalidate_path] => [opcache.log_verbosity_level] => 1 [opcache.memory_consumption] => 134217728 [opcache.max_accelerated_files] => 4000 [opcache.max_wasted_percentage] => 0.05 [opcache.consistency_checks] => 0 [opcache.force_restart_timeout] => 180 [opcache.revalidate_freq] => 2 [opcache.preferred_memory_model] => [opcache.blacklist_filename] => [opcache.max_file_size] => 0 [opcache.error_log] => [opcache.protect_memory] => [opcache.save_comments] => 1 [opcache.load_comments] => 1 [opcache.fast_shutdown] => 1 [opcache.enable_file_override] => [opcache.optimization_level] => 2147483647 ) [version] => Array ( [version] => 7.0.2-dev [opcache_product_name] => Zend OPcache ) [blacklist] => Array ( ) )
This will return that holds information about whether the opcache is turned on or not, whether it’s in a restart phase, the memory usage and hit statistics, and any files that have been cached along with hit and memory details. For example:
Array ( [opcache_enabled] => 1 [cache_full] => [restart_pending] => [restart_in_progress] => [memory_usage] => Array ( [used_memory] => 9395880 [free_memory] => 121987104 [wasted_memory] => 2834744 [current_wasted_percentage] => 2.1120488643646 ) [opcache_statistics] => Array ( [num_cached_scripts] => 353 [num_cached_keys] => 1546 [max_cached_keys] => 7963 [hits] => 27055 [start_time] => 1365412384 [last_restart_time] => 0 [oom_restarts] => 0 [hash_restarts] => 0 [manual_restarts] => 0 [misses] => 509 [blacklist_misses] => 0 [blacklist_miss_ratio] => 0 [opcache_hit_rate] => 98.153388477725 ) [scripts] => Array ( [/http/includes/libs/ZF-1.12.2/Zend/Loader/Autoloader.php] => Array ( [full_path] => /http/libs/ZF-1.12.2/Zend/Loader/Autoloader.php [hits] => 175 [memory_consumption] => 63320 [last_used] => Mon Apr 8 16:21:14 2013 [last_used_timestamp] => 1365434474 [timestamp] => 1343660895 ) [/http/www-includes/libs/ZF-1.12.2/Zend/Db/Adapter/Oracle.php] => Array ( [full_path] => /http/libs/ZF-1.12.2/Zend/Db/Adapter/Oracle.php [hits] => 17 [memory_consumption] => 60600 [last_used] => Mon Apr 8 16:21:14 2013 [last_used_timestamp] => 1365434474 [timestamp] => 1325795702 ) [/http/libs/ZF-1.12.2/Zend/View/Helper/Placeholder/Container.php] => Array ( [full_path] => /http/libs/ZF-1.12.2/Zend/View/Helper/Placeholder/Container.php [hits] => 175 [memory_consumption] => 2744 [last_used] => Mon Apr 8 16:21:14 2013 [last_used_timestamp] => 1365434474 [timestamp] => 1325795702 ) ... ) )
APC did have a GUI which was quite handy to see what had been cached, settings and memory usage but Zend OPcache doesn’t (currently as far as I could see) have anything similar.
It is possible to get information from looking at the output of phpinfo() which contains all of the key information.
However, I’ve just pushed the start of a GUI to GitHub. If you want to make changes and improvements then please feel free! It’s only had a very little amount of work done on it so far so is pretty raw.