QuicksearchShow tagged entriesCategories |
Tuesday, November 3. 2009
Multiple PHP versions on one webserver Posted by Mark van der Velden
in Apache, PHP, PlanetPHP at
08:39
Comments (7) Trackbacks (0) Multiple PHP versions on one webserverIntroductionThis is a blog about running two PHP versions on one webserver and using multiple php.ini files, this combination can be a tricky one to tackle. But luckily one we can tackle quite easily as long as one of the PHP versions is >= 5.2.7. For this example I'll be using Apache, but the webserver flavor doesn't really matter. The most important part is the "PHP_INI_SCAN_DIR" environment variable. The whyThere could be a number of reasons to want what I'm about to talk about. In my case I have a project where I have a legacy code-base, running on a specific PHP version, and a new code-base which will be run on 5.3. Because the new code-base will be a ongoing progress of replacing the old, it first has to run side by side with the legacy code-base. So I wanted my development image to run two PHP versions. The old code-base used php.ini settings such as a include-path, error reporting, etc. Which will be different from the new code-bas, and those can no-longer be set with the 'php_value' feature of Apaches since the PHP version we'll be using for that runs as (f)CGI rather then as module. Thursday, October 29. 2009
Javascript printing a popup window Posted by Mark van der Velden
in Javascript at
15:25
Comments (2) Trackbacks (0) Javascript printing a popup windowFor the impatient, a working example:http://dynom.nl/jquery/print_popup.html
It seems so easy, but I had some trouble printing a popup window containing an image. Whenever I printed the page using the following code it failed. /** * FAIL */ function printIt() { var win = window.open('/path/to/image.jpg', 'Image', 'resizable=yes,...'); if (win) { win.focus(); win.print(); } return false; }
So I changed from opening a URL to writing a IMG tag to the opened window, which works like a charm. /** * Works like a charm. */ function printIt() { var win = window.open('', 'Image', 'resizable=yes,...'); if (win) { win.document.writeln('<img src="/path/to/image" alt="image">'); win.document.close(); win.focus(); win.print(); } return false; }
And to put it in jQuery terms: /**
* To put it in jQuery terms: */ Popup = { init : function () { $('a#action_print').bind('click', Popup.printIt); }, printIt : function () { var win = window.open('', 'Image', 'resizable=yes,...'); if (win.document) { win.document.writeln('<img src="'+ $(this).attr('href') +'" alt="image" />'); win.document.close(); win.focus(); win.print(); } return false; } } $(document).ready(function () { Popup.init(); }); Sunday, October 11. 2009
Multiple backend session storage handler Posted by Mark van der Velden
in PHP at
11:17
Comments (0) Trackbacks (0) Defined tags for this entry: backend, driver, loadbalancing, php, session handler, session_set_save_handler, state, write trough
Multiple backend session storage handlerRecently I got asked if I knew about a system that supports multiple session back-ends at once. I didn't know about one and since it's not rocket-science I decided to spent a few hours and whoop something up. For the impatient, checkout: http://github.com/Dynom/SessionHandler What does it do?It is a drop-in high-availability storage back-end for PHP sessions by offering a redundant session storage system. It's as easy as including the lib, define the drivers you want to use (e.g. Memcache and MySQL) prepare their configuration/installation and done. If you already have a MySQL server and a Memcache instance running you can set it up in about 5 minutes. It's also easy to extend and write new drivers, just extend the template class and fill in the blanks. Continue reading "Multiple backend session storage handler"Tuesday, October 6. 2009
Sorting of lists in jQuery Posted by Mark van der Velden
in Javascript at
13:00
Comments (0) Trackbacks (0) Sorting of lists in jQueryA while back I posted a simple sorting algorithm for number sorting, but it doesn't really do the trick for regular strings (e.g. anchors). But since I needed one recently I wrote another small and very simple sorting solution. For a working example, see: http://dynom.nl/jquery/listsort.php My.List = { Sort : function (listSelector) { var sortedElements, left, right; // If we have any list items to sort on if ($(listSelector + ' li').length > 0) { // Remove the items from the DOM sortedElements = $(listSelector + ' li').remove(); // Sort, using a custom sorting and compare by anchor contents sortedElements.sort(function (a, b) { left = $(a).children('a').html(); right = $(b).children('a').html(); if (left > right) { return 1; } else if (right < left) { return -1; } else { return 0; } }); // Place the items back on the DOM $(listSelector).append(sortedElements); } } }; Again, the source should be self explanatory
Tuesday, October 6. 2009
Click many, call once with jQuery Posted by Mark van der Velden
in Javascript at
12:28
Comments (0) Trackbacks (0) Click many, call once with jQueryRecently I wanted to improve they way some anchors where handled in my recent project, it works a bit like adding and removing items to/from a list. But it was possible to trick the interface by quickly clicking multiple times on a link before the AJAX request was finished, while the back-end handled this without any problems, the interface for the visitor couldn't. And since I'm a neat freak and I had a few minutes to spare, I came up with the following. A working example: http://dynom.nl/jquery/clickmanycallonce.html.
My.items = {
init : function () { // Bind the real item only once, and the dummy item permanently // This way the *real* item is only called once, regardless of the amount of clicks // And the link remains clickable but doesn't trigger the browser to follow it. $('ul>li>a.item').one('click', My.items.real_action).bind('click', My.items.dummy_action); }, dummy_action : function () { $(this).html( $(this).html() + '.' ); return false; }, real_action : function () { /* Fancy AJAX call, that shouldn't be executed more then once for every click */ $('div#frame').html($('div#frame').html() + "<br>\nCalling 'real_action' for anchor: " + $(this).html()); return false; } }; // When the DOM is ready $(document).ready(function () { // Attach the filter to our input and list My.items.init(); }); While the code is fairly self explanatory and quite simple here the steps in a bit more detail:
This situation is probably only favorable if the item you click is removed from the DOM (or has actions re-bound after the call) else it might not be what you want. Friday, September 25. 2009The PHP Quiz seriesI like solving puzzles, probably one of the reason why I like programming as much as I do. I also like finding challenges and experimenting, as such I came to the idea to start the PHP Quiz series. They contain typical combination of PHP quirks and lesser known features of PHP. The reason behind the quizzes is not to advocate bad or good coding practices, but it's intended to let you find out the why in all of it. I believe that by understanding what happens it can make you a better programmer and you might spot bugs easier then without knowing what happens. The series are not ordered in level of difficulty but merely in the order that I found out about them, thought about them or where simply sent in. But in general I think it's safe to say that your knowledge of PHP should be quite a leap forward from novice before you can answer most questions. This however doesn't mean that, once you can do the quizzes flawlessly, that you are a superior programmer. There is a big different between knowing how to design an application and knowing why $array = array(1,1) + array(2,2) only results in an array with two elements. An overview of all the PHP Quizzes: http://blog.dynom.nl/categories/PHPQuiz_12
-D Monday, September 21. 2009
PHP Quiz part 3 Posted by Mark van der Velden
in PHP, PHPQuiz, PlanetPHP at
17:35
Comments (2) Trackbacks (0) Defined tags for this entry: form, php, php quiz, phpquiz, planetphp, precedence, references, string, unset cast
PHP Quiz part 3Welcome to another part of the PHP Quiz series, again some interesting questions to crack your brain about. If you have some nice additions or questions, be sure to leave a comment. Enjoy part three! As always, think of the answer before you execute the code or look it up. You can find round two here. Unset castWhat is the type of $a and what is the type of $b Form funWhat will the output be? <form method="post" action="" enctype="text/plain">
<input name="search" type="text"> <input type="submit"> </form> <?php error_reporting( E_ALL ); echo (string) filter_input(INPUT_POST, 'search'); ?> Fun with stringsStrings in PHP are versatile, but how versatile are they... What will the output be? $juggling = "Itffkhmf";
Continue reading "PHP Quiz part 3"$rox = "Spy"; $b = $c = ""; for ($i=0; $i<strlen($juggling); $i++) { $b .= $juggling[ $i ]; $b++; } for ($i=0; $i<strlen($rox); $i++) { $c .= $rox[ $i ]; $c--; } var_dump( $b, $c ); Sunday, August 30. 2009
New airfilters and map update Posted by Mark van der Velden
in Motorbike at
23:06
Comments (0) Trackbacks (0) New airfilters and map updateLast Saturday I went for new air filters and a new (injection) mapping. I was planning to get that done anyway, but then I decided to update my blade with two K&N filters also. Slightly more performance and little to no more maintenance needed in the future regarding that area. (And honestly, while the filters are much more accessible then at my previous bike. It's still not the most fun part to clean.) After approx. 2 hours they finished tuning and she took one more run on the Dynojet. A total of 165 bhp on the rear wheel and (the most valuable part) a much faster throttle response and better power outtake. It was costly for something that seems minor, but as soon as I drove off and noticed the difference it was all worth it! Wednesday, August 5. 2009
The way a developer community works Posted by Mark van der Velden
in Social at
13:00
Comments (2) Trackbacks (0) The way a developer community worksI was watching the talk "Standing out in the crowd" by speaker Kirrily Robert at OSCON 09. And tweeted about this (http://twitter.com/Dynom/statuses/3142970947/) and when I read it back it got me thinking. And I decided to blog about it. Much of what Skud (Kirrily) says is without a doubt true, but doesn't apply sole to women. It's generally the way it "works" in the open source world and between developers in general. There is a certain attitude that is simply there, not just between language fanbois but also between developers in general. Your sexual orientation, sex, hair color or religion has nothing to do with that. Partially I think the attitude is there to improve yourself, at least that's how it works for me. You try to be as good as the one you think is better then you are. In a lot of communities, you don't explicitly mention your gender. You simply join a community (subscribe to a form or e-mail list) and you start posting/reading etc. And unless your nick is 'Girlygirl99' it's not too obvious in name also, so I wonder how people treat anyone based on their online identity. Feel free to prove me wrong on that, it's not that I don't believe it, I simply have never seen discrimination towards sex or sexual orientation in any community I've been in. And maybe it differs a lot per community, I'm involved in the PHP community and from what I hear it has a small percentage PHP developers that are female, and they even have their own "support site" PHPWomen.org. And they seem to do pretty well. As Skud quotes in her talk, some projects have a "diversity statement". I think it's nonsense to mention it at any community/project. It should only be mentioned if it doesn't say "everyone". If you want to be part of a community, simply step in. Order a beer, listen and join the conversation. If you lack the assertive skills to do that, it's not something the community can do about. It's something you need to improve on. If a community helps beginners, well that is a (big) plus. Personally I don't care what you are, as long as you aren't (secretly) part of Skynet. Comments are more then welcome. Sunday, July 12. 2009
Taking her for a dyno run Posted by Mark van der Velden
in Motorbike at
14:29
Comments (2) Trackbacks (0) Taking her for a dyno runYesterday I took my new bike for a spin on a Dynojet. I did this for a number of reasons, since I didn't bought the bike from a dealer I didn't know for sure if the bike was in perfect shape, and also I wanted to know how much *real* BHP it has, since the bike is slightly tuned (Power commander and Termignoni exhaust), which is definitely not stock. The score was excellent, according to the readout my blade has 161BHP on the wheel (which is proximately 10% less then on the crankshaft, which is mostly used to indicate the power) and performs really nice, the graph shows a near linear output of power, no dips anywhere along the way which is simply near ideal. However there is some misconfiguration between 4k-6k rpm, the fuel maps are not rich enough, which is something that needs correcting! So I'll make an appointment for a followup meeting with the tune company to create a custom map for my bike. |
Calendar
|
||||||||||||||||||||||||||||||||||||||||||
