Full-Service Internet Marketing & Web Development | WebMail
Call us Toll-Free:
1-800-218-1525
Email us

How to call a shell MySQL process from PHP

Mike Peters, October 17    --    Filed under Programming
Spawning a shell MySQL process from PHP is easy. All you have to do is -


exec
("mysql -uUSERNAME -pPASSWORD < inputqueries.sql");

But how do you know if the command went through successfully? What if the username was invalid? Or a MySQL error in inputqueries.sql?

The trick is to redirect stderr to stdout and save it into a response text file.

The code below does the trick:


// Run command
exec("mysql -hHOST -uUSERNAME -pPASSWORD < /FULLPATH/inputqueries.sql 2> /FULLPATH/response.txt", &$output);

// Check response.txt file for errors
$file = @fopen("/FULLPATH/response.txt", "r");
if (
$file)
{
   
$buf = fread($file, 4096);
   
fclose($file);

   
// If we have a MySQL error - it will be in response.txt
    // If response.txt is blank, it means no error
   
if (strlen($buf)>2)
    {
       
// Display error and bail
       
echo "ERROR: $buf\r\n";
        die;
    }
}

// If we're up to here - all is well
// The query was processed successfully
echo "Success\r\n";

Two things to note:

#1. Always use full file paths
#2. Be sure to use 2> and not just > when redirecting the output to the response.txt file

Average ROI per Marketing Channel breakdown

Adrian Singer, October 16    --    Filed under Analytics
SoftwareProjects is a full-service Internet Marketing & Web development firm, supporting 3,000 businesses in 14 countries.

With $600M of Internet Marketing budgets under management and $1 billion in orders going through our shopping cart system, we learned a thing or two about what type of marketing works best for each industry.

Over the last few days, we dug deep into our analytics to come up with aggregate data that would answer two very popular questions we get asked a lot -

1. "What type of ROI can I expect on my marketing dollars?"

2. "Which marketing channels should I target? How should I divide my budget across the different channels?"

When I volunteered for this project, I didn't realize the amount of work that would go into dissecting the analytics for about 2,400 companies we had data for.

We service a variety of different industries and every industry is unique. I quickly decided to focus on 4 popular industries and began crunching the numbers, with the help of an engineer.

Without further ado, I'm proud to present to you the results of our findings -

Distribution of Marketing budget by Industry



Average ROI by Industry



Notes:
* We highlighted the top channels for each industry in yellow.
* ROI of 100% is break-even. ROI of 3% means the company generated a 3% return on its marketing dollars, losing 97% of its investment.

View 5 Comment(s)

Memcached for PHP Sessions

Dawn Rossi, October 14    --    Filed under Programming
Sessions are a great way to store data pertaining to a single end-user browsing through your site, before the user logged in.

Each user is assigned a unique ID and that ID serves as the key to a dataset, where you can store the user name, email address, referral, affiliate_id etc.

Since sessions are accessed on every page load, it is important to optimize the amount of time it takes to read/write sessions.

PHP sessions can typically be stored as either files or database records.

Files are fast, but don't allow you to scale beyond a single server.
Database records support scaling but are "expensive" to read/write.

As part of this post, I will walk you through the process of using Memcached for PHP sessions.

Memcached is a very efficient in-memory database that supports scaling to multiple machines, expiration and built-in garbage collection. We're going to hit Memcached first on all session queries. If we don't have a match, we read it from the database (once) and store the information into Memcached for later fast retrieval.

Step 1: Install Memcached

Step 2: We're going to use PHP function overrides feature and define new session handling functions. Save dbsession.php in your includes directory and replace all references to "payments" with the name of your global database.

Step 3: Create the sessions table under your global database:


CREATE TABLE sessions
(
session_expire int(11) unsigned NOT NULL DEFAULT '0',
session_value longtext,
session_key char(32) NOT NULL DEFAULT '',
PRIMARY KEY (session_key)
)

Step 4: Save common_cache.php under your includes directory. This file is used by dbsession.php and serves as the wrapper class for accessing the Memcached server. Update the array at the top of common_cache.php with the ip addresses of your Memcached servers. You can have multiple Memcached servers and as long as they're all aware of each other, everything will scale gracefully.

Step 5: Include dbsession.php at the top of your php files (or add it to one of your global includes that is included everywhere). Make sure you include dbsession.php before the first call to session_start

All it takes is a single include at the top of your php files and voila - all sessions are now handled by Memcached first, then reverting to the database if no match found.


require_once("dbsession.php");


View 7 Comment(s)

Add Live OnDemand Chat to your website

Sisse Naggar, October 14    --    Filed under Conversion
Live Chat is a great way to let customers connect with you at different stages of the sales process.

Pre-sales: Answer any questions customers have prior to placing an order on your website. Alleviate concerns and provide incentives to buy now. Goal: Increase conversion rates.

During sale: Answer questions about up-sell items and present special offers. Goal: Increase upsell rates

Post-sales: Customer support. Goal: Reduce refunds, Improve retention rates

Robot vs Human

If your goal is to increase conversion rates and you're low on staff, one solution you may want to look at is employing a robot chat. Robot chat is a system designed to appear to the end-user as if they're chatting with a live person, where in fact, all responses are pre-programmed to match common questions customers may ask.

The industry leader in robot chat (also known as "automated sales agent") is IntelliChat.



IntelliChat is low-cost, easy to setup and in our tests, proven to increase conversion rates by an average of 5 to 10%

Human chat, on the other hand, allows your staff members to personally converse with end-users as they visit your website in real-time. Pros: Answer any question with a personal touch, learn more about your customers. Cons: Need staff members readily available during normal business hours.

How it works

Integrating live chat into your website takes a few short minutes. You will be provided with Javascript code to install on the pages where you'd like to make live chat available.

The system can be configured to proactively engage the user if they spend more than X seconds on a page without taking action, or wait until users click the chat button to initiate a dialog.

LivePerson

Over the years, we had a chance to test a variety of chat systems. Javascript based, ActiveX, downloadable, Ajax and basic html chat widgets.

Out of all the systems we tested, LivePerson is the clear winner in features, compatibility and stability.

LivePerson works well whether you have a single chat agent or 200 agents. Compatible with all browsers and offers an impressive set of back-end reports, SLAs, skillsets, built-in knowledge base, analytics and co-browsing.



Another really cool feature of LivePerson is that it lets you see visitors to your website in real time. Where they came from, what page they are currently browsing and what they're clicking on. This is a goldmine to marketers.

LivePerson is tightly integrated with the SoftwareProjects Shopping Cart. You can see a demo of the system here or contact your SoftwareProjects account manager to setup a test drive on your website.

Cost

LivePerson starts at $99/monthly per agent. Volume discounts are available. No setup fees.

As part of the setup process, your SoftwareProjects account manager will configure the system and train your staff members on how to use the chat system, view reports, setup skill levels etc.

View 2 Comment(s)

Upgrading to Nginx 0.6.32 fixes memory leaks

Dawn Rossi, October 14    --    Filed under Programming
Nginx is a super fast unix web server (Apache replacement) that is capable of delivering 10x throughput compared to Apache.

Unlike Apache, Nginx does not spawn a separate process per each connection and is much more lightweight.

Recently one of our older Nginx machines (0.5.3) began exhibiting severe signs of memory leaks. Memory use would spiral into the %90+ and the web server started responding with 504 gateway errors.

I upgraded to the latest stable version of Nginx (0.6.32) by following this guide and the memory leaks appear to have gone away.

See screenshot below from our server monitoring app. Notice the big drop in memory utilization around 05:40am



More information about Nginx:
* Installing Nginx Web server with PHP and SSL
* How to install Nginx, PHP, FPM and MySQL
* How to upgrade Nginx with no downtime
* Make your site run 10 times faster

MySQL 1 Million Rows Golden rule

Dawn Rossi, October 10    --    Filed under Programming
According to MySQL documentation there are no software limits on the number of records per table. Some users report using MySQL with 50 million records and more.

Here in SoftwareProjects we found it's okay to use MySQL "archive type" tables with tens of millions of records, but for all active tables where you're constantly inserting, updating, deleting and querying the table -

Do NOT load up more than 1 million rows into a MySQL table.

We measured a considerable performance degradation whenever there are more than 1 million rows in an active (busy) table.

If you need more than 1 million rows, look into: partitioning, sharding or a purge script that will move unused rows to an archive type table.

« Previous Posts » Next Posts


About us  |  Contact us  |  Privacy  |  Terms & Conditions  |  Affiliates  |  Advertise

© 2008 Software Projects Inc. (SPI) 2
Friday, November 21st, 2008
Page generated in 0.011 seconds