Saturday, September 12, 2009

Starting another script

I have a PHP script that customers would use to start a process. The process was time-intensive, so I had it start another script in the background. It was important that the customer did not have to wait until the long process ended. After trying a few things, I found a forum that gave me my solution (sorry, can't find where it is anymore). This starts a PHP script in the background from within another PHP script:
shell_exec('php /public_html/accountname/longProcess.php > /dev/null 2>/dev/null &');

Simply replace the script name with our own and it should work (note: not sure if the whole path is required). What this does is force the standard output and error output to be discarded and the final ampersand causes it all to be run in the background.

Tuesday, September 8, 2009

TinyMCE Spell Checking

In my last post I talked about the HTML/Rich-Text editor called TinyMCE. I have used it on a few sites for content management. Well, today I've learned of a plug-in for TinyMCE that is very promising.

This plug-in is a spell and grammar checker called After the Deadline. It is free for personal use, and from some of my limited tests it appears to be very powerful. I read on TechCrunch that it was recently acquired by WordPress co-founder Matt Mullenweg and is already enabled for users on their platform.

Need a spell checker? Check it out: http://www.afterthedeadline.com/

Thursday, September 3, 2009

Text Area to HTML Editor

TinyMCE is my visual HTML editor of choice (a.k.a. What You See Is What You Get or WYSIWYG). I use it on a number of websites to allow customers to update content without needing to take a class on HTML and CSS. It has worked pretty good for me thus far and best of all, its free.

One particular feature that I've recently discovered has made me pretty happy. TinyMCE allows me to supply a list of URLs for TinyMCE to make available when a user wishes to insert a hyper link. This is a beautiful thing. Before the user had to copy and paste every URL they wanted to link to.

Just as cool is that I can also supply a list of images and videos that can easily be inserted (no copying and pasting these URLs either). So after uploading an image to the server, they can edit a webpage and TinyMCE already has this image's URL ready if it is to be used.

In order to do all this, at the end of my TinyMCE initialization script I added these three lines:

<script type="text/javascript">
tinyMCE.init({
...
external_link_list_url : "/tiny_mce/links.php",
external_image_list_url : "/tiny_mce/images.php",
media_external_list_url : "/tiny_mce/media.php"
});
</script>

Now, on the other side of these specified URLs I have a PHP script that rounds up every URL (or image or video) on the server and provides it in a JSON encoded list for TinyMCE. This way, when a user wants to insert a link (or image or video), TinyMCE already has a good list of links that the user can choose from.

Let's assume, for the PHP example script, that you have a 2D PHP array called $linkOptions that had every link the user might want to use. Here is a part of links.php, specified above:

<?PHP
header("Content-type: application/javascript");

echo "var tinyMCELinkList = new Array( \n\t";

$firstLink = true;
for ($j = 0; $j < sizeof($linkOptions); $j++) {
// Go through each link of the array
if ($firstLink) {
echo "\n\t"; // No comma for the 1st
$firstLink = false;
} else echo ",\n\t";

echo '['. htmlentities($linkOptions[$j][0]); // Link Name
echo '","'. htmlentities($linkOptions[$j][1]) .'"]'; // Link URL
}

echo "\n".');'; // All done

Then, you would need to do replicate something like this for each of the link lists specified. Hope you find this feature as useful as I. Good luck!

PS. TinyMCE is also the HTML editor used for WordPress.

Tuesday, August 25, 2009

Domain Renewal Group

This company has such awful business practices, I have to make a quick entry about. Today I received a bill-like letter in the mail from Domain Renewal Group (the same company as Domain Registry of America). In the letter they say that my domain name is expiring soon (as in 5 months from now) and that I should renew with them today. But, they are not the company I originally registered with nor would I ever want to (their fees are ridiculously high).

It is clear that Domain Registry of America has made a conceited effort to trick people into paying them through what appears to be a bill. They do say that "This notice is not a bill" but it is buried in the middle of a wordy paragraph, where it will be easily missed. I personally know of one organization that unwittingly sent them money, thinking that they were obliged to do so. Instead they fell for what amounts to a dirty scam and wasted their money. (Unfortunately their IT people were not consulted by their accounting people.)

So, if you get a fake bill from Domain Renewal Group, toss it in the garbage and maybe write your own review of this unethical company.

Other related sites: Domain Registry's BBB record, Dynadot's warning (a good registrar), and an understandably frustrated blogger.

Saturday, August 22, 2009

CSS: inline-block

So much time spent on one CSS statement - "display: inline-block;"

This statement is perfect for a new site I am working on. I want three columns of data to display side-by-side. But, I had many frustrations trying to get it to work cross-browser. This is what I found...

Inline-block works great on IE 8, Chrome and recent versions of Safari.

I had issues when it came to IE6 and IE7, no big surprise there. I fixed this with some conditional comments and the CSS property "display: inline" which acts the same as inline-block in IE.

I also had problems with Firefox 3! My old love of a browser takes issue with this statement (when used with other specific statements). Apparently "display: inline-block" does not play nice with "overflow: hidden" and "text-align: center". This strange alignment of the planets causes my text to align left, instead. Quirky. I ended up commenting out the overflow property, and everything worked for Firefox 3. (I also added a strange Firefox style statement to make sure it worked on FF 2: "display: -moz-inline-stack;".)

Thursday, August 6, 2009

Group text messaging

Just recently ShortShout has been released to the world, so I thought I'd give it a mention here. ShortShout is a group texting manager. It is a great way to keep groups up to date on events and changes and other things. It allows group leaders to send out SMS messages to everyone who subscribes. I originally designed it for my youth group. I found that many of the youth didn't check their email very often at all–and I think this is true for most people in general. But, they did check every text message they got. And that's what makes ShortShout such a great tool. You can send messages to people and not only are they read, but they are read almost as soon as they are sent. You can't beat that. This makes ShortShout a great tool for all kinds of groups, from youth groups to bowling leagues, basketball leagues to office pools. Check it out: http://shortshout.com/

Friday, July 17, 2009

Scaling

Sometimes in life we have to face good problems -- problems that we are happy to have. One such problem is scaling. And it is only really thought about when your website is doing well and receiving a lot of traffic. Thus it is a good problem.

Here are some tips to scaling well and enabling your website to grow large, easily. (By the way, I am assuming a LAMP configuration.)

  • 1. Be very careful using session data (e.g., $_SESSION['varname']), because if you ever need to expand to multiple web servers, this wont work. Session data is stored in memory and will not be present if the web visitor would happen to use a different server for a second request.

  • 2. I know this is common practice, but I will repeat it anyway: Use library and include files for your scripts. In these files include common functions and common parts of your rendered pages (e.g., headers, menus and footers). This makes updating your entire website as simple as editing one file.

  • 3. Plan ahead for major traffic spikes by using grid hosting (e.g., Media Temple's "Grid Service"). Grid hosting is a deal where server resources are pooled together and used for whatever site needs them. This way, when you get a major spike in traffic (e.g., you get slashdotted), you have ample processing power and bandwidth to handle it. You may have to pay a bit more when you get traffic spikes, but it is better than being suspended by your host.

  • 4. Deliver your media content on another set of servers. Media files like movies and audio can take up a lot of bandwidth and file space. Whenever possible offload these files on to someone else's site and you'll save some cash and be more scalable. For example, upload your movies to YouTube or Vimeo and then embed their flash players in your own site. Alternatively, you can use a Content Delivery Network or something like Amazon's S3. When you host content with any one of these solutions you also gain in the area of speed and quality of delivery.


There is a lot more that can be said in this area, but these are the things I've come across that have helped me.