Wednesday, June 24, 2009

Learning on the Fly...

Well, the test server has not completely been rebuilt, so I have to move on. On the production server, I attempted to install the needed Perl modules and ran into several snags. Some of them won't compile.

So, I need to back up a bit. I hate having to learn a language on the fly, but it won't be the first time. The procedure that I have is written in Perl, and so I need to write it in PHP.

If you don't know what PHP is, it is a scripting language to generate dynamic web pages, with its interpreter written in C++. It originally stood for Personal Home Page, but has moved away from that. A lot of the syntax is similar to C++, so it should not be too hard, right?

So, I'm looking for the right "...Dummies" book to give me what I need -- PHP and SOAP messages over SSL. If you know of any, please comment. Anyway, I'll most likely have to pick and choose from the Internet, like always. :-/

For example, I've written some JavaScript code to allow tab key input into a text field for forms, taken from here and there on the 'net. Found one code, that didn't work correctly, but I took that and ran with it (I don't remember who I got it from, so if it was you, sorry and let me know). Fixed it and it works great! The tab character is inserted into the text at the current cursor position.

The only problem is, the code that I have only works in IE. Since that is the accepted browser where I work, there is no immediate need to go further, but I would like more.

Here is the code:

<script language="JavaScript">
<!--
function storeCaret(textEl) {
if (textEl.createTextRange)
textEl.caretPos = document.selection.createRange().duplicate();
}
function insertAtCaret(textEl, text) {
if (textEl.createTextRange && textEl.caretPos) {
var caretPos = textEl.caretPos;
caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ? text + ' ' : text;
}
else
textEl.value = text;
}
function onKeyDown(textE2) {
var e = window.event;
storeCaret(textE2);
if (e.keyCode == 9) { // tab
insertAtCaret(textE2, "\t")
e.returnValue = false;
}
return true;
}
// -->
</script>



And all you have to do to get it to work is use the onKeydown="onKeyDown(this);" event handler on the text area you want to use it in.

If you know how to make this work in Netscape, let me know and I promise I will give you credit!!

PS. If you would like me to make the code available online, I'll figure something out (just tried to cut-n-paste and that sucked).

PPS. The limited control over text spacing here sux!

3 comments:

Planetx_123 said...

Im on the way out the door to work, so I don't have the time to look at your js-- I will try later.

For SOAP messaging in PHP- I always have used nuSOAP. There are a few libraries out there but nuSOAP has always been the best for me. There are few gotchas depending on what type of WS you are trying to call (the standard WS generated by .NET have a little quirk that nuSOAP hits).

PHP is trivially simple-- especially if you know PERL! Perl is the most un-maintainable language I have ever used. While I give it the respect it deserves being that it was the best solution for a long time... its not any longer. Python offers an excellent full featured string parsing functionality that Perl has always claimed to fame. Powershell also has great string parsing capabilities (And has many of the language features of perl, but still seems more maintainable over Perl).

Anyways good luck with your work; I have a 1M LOC codebase I am in the middle of refactoring... its going to take some time :-)

Much Love,
Steve

Ray's Blog said...

Thanks Steve for your comment. I did run across nuSOAP when querying Google and am looking at the docs now.

One thing simple is (as per say), PHP does XML v1.0 by default, and that is the same with Remedy (the ticketing system we use) midtier. What I'm afraid of is that Engineering is thinking of upgrading, and that *might* force me to update the XML parser that comes with PHP to v2.

The PHP book I have is very basic and so I know that I need something more. I hate it when they add the text “…this is beyond the scope of this book…” I generally rate a book down the more they use that term, and so far they’ve used it five times already and I’m on chapter 12.

So far, I’ll miss the buffering the output that ASP does for you (unless PHP does this, and the author of the book has decided that it is beyond the scope of book…).

Gotta run, late as it is.

Planetx_123 said...

Right but what style of webservices are you using are you using full blown SOAP WS or RPC over XML (lightweight WS)? If the latter, then yes maybe just handling it yourself is easiest. If you have to deal with soap envelopes, WSDL, mime types, etc. you will want to use a library. There are other libraries besides nuSoap, and I think there are some modules that can be compiled in that are better than nuSOAP. I just used nuSoap because it could be deployed and used without affecting the PHP install (which on shared hosting, which was my target paltform, is impossible to deal with).

Oh- btw- PHP does have output buffering. ob_start and ob_end_flush (ob stands for 'output buffering'). One common pattern for PHP apps is to use the 'front controller' pattern so that all incoming requests funnel through the same common gateway so you can handle your request lifecycle nicely (i.e. start_session, ob_start, etc.).

now begins a rant about technology frameworks. I can go for days... I am passionate :-)

php vs asp is an interesting topic. I use php for contract work, small websites that are going to be targetted to shared hosting services. This is really the kind in this space, and php has some nice frameworks that makes it less painful to manage codebases (the Zend framework comes to mind...) Asp.net is nice, and obviously if your a MS shop, or have more IT guys that do development instead of just developers then its a great choice. Microsoft does an excellent job retaining their development base and disseminating information to their devs. I was a 'MS developer' for a while in college (when I did IT work). However, when it comes to real enterprise web development and server side development the Java ecosystem dominates MS in every way. MS just cannot keep up with
'the world' in enterprise level technology. They are behind on everything. They get the benefit of learning from many of the mistakes of the 'bleeding edge', but they trail by a good margin sometimes. For example, distributed shared caching technology is becoming more and more relevant to driving solutions to market quicker with better scalability. Java has had DSO technologies (many of them: terracotta, tangosol, gigaspaces, etc) for over 4 years now so they are mature and in the market. MS just recently released the first CTP of their DSO technology (called Velocity if you keep up with MSDN magazine). I saw a lot of good things in their approach, and hopefully they can add something that will cause java to have to compensate (like C#, which is and has been a superior language to Java since .net 2.0... note just language not platform). Ok I should stop now :-)

Good luck- let me know how it turns out, and feel free to send me an email if the book is laking. I wouldn't call myself a php expert. I have spent a significant amount of time writing in PHP and have used most of the features of the language from mundane stuff to its (sometimes strange) OO support.

Steve