PHP and javascript timestamper

This is an extension of an earlier script to demonstrate the difference in execution time of preg_replace and trim.

The objective of this demonstration is to show a quick time check method to determine the following:

  • Time required for PHP to process all statements
  • Time required for javascript to process all statements

This code is valuable for complex pages, specifically RIA pages, to assist engineers in finding ways to make the page display more quickly.


/* First line of the PHP script */
$fStartPHP=microtime(true);

/* Beginning of the HTML */
echo '<html>';

/* This captures the time the first javascript statement was executed */
echo '<script>var d=new Date();var jsStart=d.getTime();var jsEnd;</script>';

/* This captures the time the page has finished loading.  If other code is executed prior to the page being considered fully rendered and functional, the EndLoad function should be called after the last statement */ 
echo '<script>function EndLoad(){var d=new Date();jsEnd=d.getTime();jsElapsed=jsEnd-jsStart;document.getElementById(\'jsStartDisplay\').innerHTML=jsStart;document.getElementById(\'jsEndDisplay\').innerHTML=jsEnd;document.getElementById(\'jsElapsedDisplay\').innerHTML=jsElapsed;}</script>';

/* Body tag */
echo '<body onload="EndLoad()">';

/* At the end of the PHP script */
dd
$fEndPHP=microtime(true);
$fPHPElapsed=$fEndPHP-$fStartPHP;
echo 'PHPStartTime: ';printf("%f",$fStartPHP);echo '<br />'."\n";
echo 'PHPEndTime: ';printf("%f",$fEndPHP);echo '<br />'."\n";
echo 'PHPElapsed: ';printf("%f",$fPHPElapsed*1000000);echo ' microseconds <br />'."\n";
echo '<hr />';
echo 'HTML/JSStartTime: <span id="jsStartDisplay"></span><br />'."\n";
echo 'HTML/JSEndTime: <span id="jsEndDisplay"></span><br />'."\n";
echo 'HTML/JSElapsedTime: <span id="jsElapsedDisplay"></span>&nbsp;microseconds<br />'."\n";
echo '</body>';
echo '</html>';

Great Viral Marketing

This link allows you to enter a name and an email address and makes a great video promoting the person as a Presidential candidate.

The whole concept is excellent for the following reasons:

  • It is fun, and funny.
  • It is timely.
  • It is free.
  • It encourages people to enter their friends’ name and email addresses.

Unfortunately, they don’t have a free demo, so you can see the final product. This is one that was posted on YouTube.

The company gets people to see their product and have fun. They also get contact data for people.

It may be worth considering this type of marketing if you have a budget that allows it. Humor is valuable, but the real key is to engage the site visitors and to allow them to share your site’s content with their friends, without appearing too agressive. For example, if you sell hats, you could allow people to upload their photo and see one of your hats on it. Give them a link to the image and they can share it with their friends. It is more fun than ‘Tell-A-Friend’, and does a better job of highlighting your products.

This can be approached in several different ways, depending on the type of product or service you provide, and the type of people you want to attract. It can be timely, as the news3online service is, or product based, such that with new products, a new marketing adventure is offered. Publicizing the scheme might be done through PayPerClick ads - with little demos.

It is extremely important to ensure you never abuse the information entered. It may even be good to destroy it after it is used. The objective of this system is to bring people to the site, not to initiate further interaction. If you have a good site and quality products, the site visitors will see the value.

Mapping CS Courses to Internet Software Engineering

These aren’t specific courses, the intention is to provide a rough parallel. They aren’t in a particular order, and multi-semester study is implied for some areas.

  • Operating Systems - Particulary Linux. Appreciation of the hardware that makes the system work, especially the server. Understanding of the commands, organization, processing. Use of log files.
  • Computer Architecture - Key concepts - physical elements that make up the machine. Capabilities and limitations. CPUs, memory, disks, interrupts, timing, queues, caching. Performance considerations. Requirements awareness.
  • OOP / Data Structures - Ability to abstract a system into components that can be efficiently operated on. Queues, linked lists, trees, arrays, multi-dimensional arrays, matrices, classes and objects. Methods, properties and events. Vital for server and client side.
  • Algorithms - Appreciation for the impact of how code is written on performance. This is especially important because many web applications are written in interpretive languages. Awareness of high overhead operations (which can be avoided or performed by existing library functions).
  • Logic - The ability to break a problem in to manageable pieces and write efficient code.
  • Systems Analysis - Developing a high level perspective to understand how system components interface and interact. Distribution of requirements.
  • Technical Writing - Written communication is vital to describe the work that will be performed.
  • Assembly Language - A view inside the processor. Although not necessary, it is valuable to understand what the processor is, what it does, how it does it, and how to control it. Complements the OS and Computer Architecture courses.
  • Data Communications / Introduction to Networking - Writing code for the Internet is heavily influenced by its distribution. It is important to know how the data gets from the server to the client and back again. This affects how pages are constructed. Key elements, difference between form and content, compression, bandwidth.
  • Security - Use of encryption, OpenSSL, protecting data, web application firewalls, passwords, ports, server firewalls, watchdogs, etc.
  • Server Software - IIS or Apache. How requests are received, protection of data, efficient use of disk space and bandwidth. Caching. How to create and manage accounts. Use of web stats to monitor sites. Use of log files.
  • Current Industry Trends - Frameworks, template systems, AJAX, toolkits, CDNs.

More Cost-Effective Design Strategies

  • Work within application design architectures. In other words, try to use as much of their HTML and CSS as possible, or replace just the CSS. Most good applications have a nice hierarchical CSS and template organization. Learn to work with it. Many application allow the addition and removal of widgets and tools from the admin interface. Accomodate that and support it. Its is extremely valuable.
  • Use icon sets. They will allow you to provide a beautiful interface in a fraction of the time. http://www.everaldo.com/crystal/. Support these projects if possible, ask your employer.
  • Use toolkits, but carefully. If it is a simple feature, code it yourself. If it is complex, find a toolkit or javascript library.
  • Keep the layout and colors separate in the CSS. That way, you can reskin an application in different ways, easily. Use browser specific overrides where necessary.
  • If you are building an application use a hierarchical template structure and create components that can support the whole system, instead of just one page.

Web Sites - Behind the Scenes

A web site is the most visible part of a companies Internet presence, but not the only part.

The following issues must be continually addressed and frequently monitored:

  • Content Maintenance This includes all content changes. It may also require navigation changes. Many sites use content management systems such as eZ publish, Drupal, or Joomla. These make editing content easier, but still require some training. The content itself is important, but its presentation must also be considered. Web pages should be easy to read, and informative. They should be attractive and consistent with the other pages on the site. The content should be consistent with the language of the target site visitors. If it is a professional site, everything should be spelled properly, cased properly, and with valid grammar. Slang language should be avoided.
  • email Careful use of email accounts and forwarders is important. Forwarders allow the same address to deliver messages to multiple people. In addition, a forwarder can ease personnel transitions, the email address does not have to change if a different person is handling it. email accounts must be budgeted. Disk space is cheap, but it isn’t free. In most cases, the disk space used by email is deducted from the available space for the site. For that reason, one must keep track of the number of accounts and how big each mailbox is. Notification should be set up to ensure people are alerted when their mailbox is full. Issues that can take alot of time include recovering if the domain or server is blacklisted, blocked emails for various reasons, client configuration issues.
  • Contact mechanisms First, one must comply with the anti-spam laws http://www.ftc.gov/bcp/conline/pubs/buspubs/canspam.shtm. Newsletter content can also be a valuable part of a site. In addition, contact mechanisms must be protected from abuse. Tools available include CAPTCHA http://www.captcha.net/, Akismet http://akismet.com/, http://ostermiller.org/contactform/, and custom code.
  • Logs Error and access logs should be checked at least weekly for any unusual entries, for example missing pages or images. Some hacking attempts will show up in the error logs, as file not found errors - usually with distinct URLs, repeated requests into forbidden areas. Restricted areas should not be served, if they are, the web server configuration should be updated to protect them. IP address patterns should be observed to see if requests (potential attacks) are from a specific area. These can be blocked with a firewall. If you have access to the email logs and the server level logs, particularly the SSH and MySQL logs, they should be reviewed as well.
  • Application Management It is extremely important to ensure the applications are up to date. Application upgrades range from a simple button click with Fantastico to complex database and patch or upgrade sequences. As a rule, the cost of these upgrades should be included in maintenance allowances.
  • Security In the unfortunate instance when an application is hacked, it must be cleaned up, and usually the application must be upgraded. These tend to be emergencies and often result in outages. Careful Application Management (above) can greatly reduce these. Credit card and personal data must be handled very carefully (ideally by someone well-qualified :yes: ). https://www.pcisecuritystandards.org/
  • External Interfaces Many sophisticated sites have complex interfaces into payment gateways or web services. This type of code usually requires strong engineering skills.
  • SSL Certificates To support HTTPS for ecommerce and secure access to information, certificates must be purchased, approved, installed, and then renewed as required. Renewal requires reinstallation.
  • Web stat checks Periodic review of the web stats allows an evaluation of the site’s search engine positioning, sources of traffic, keywords, and pages accessed.
  • Performance Site visitors expect a timely display of a site. There are many ways to ensure a site performs well, the best solutions vary by the type of site, however, the following issues are clear: client-side caching should be used, content delivery networks are valuable for offloading the server and the network, images must be optimized - delivered properly through the server and displayed properly by all supported browsers, javascript should be portable and efficient, page construction should be evaluated with tools like http://websiteoptimization.com prior to launch and after major changes.
  • Custom code Custom code should be carefully audited for security. http://phpsec.org, http://www.fortify.com/security-resources/rats.jsp. It should be protected by a web application firewall such as http://modsecurity.org.
  • Quality Assurance Time must be taken to check the site for problems like broken links to external resources, and any problems within the site itself.
  • Technical Quality The quality of code used on a site is visible to all visitors. How it looks in the browser, and the code that delivers it should be high-quality, with current technologies applied properly. Poor displays and bad code can harms a companies reputation and professional image.