Archive for the ‘PHP’ Category

Keep Your Google Search Appliance Synced

Wednesday, April 9th, 2008

There have been a lot of people asking how they can keep their GSA synced. Here is quick, simple, and easily configurable solution that should help. Set this up as a CRON job and you’re done.

Requires: PHP, cURL

<?php
/**
* @author Chris Williams ctwilliams[at]gmail[dot]com
* @version 0.0.1
* @example php gsa-sync.php
*/

define(‘GSA_PATH’, ‘http://gsa.xyz.com:8000′); // Replace ‘http://…’ with your gsa host and port
define(‘GSA_USERNAME’, ‘user’); // Replace ‘user’ with your username
define(‘GSA_PASSWORD’, ’secret’); // Replace ‘password’ with your password

/** Define DB collections */
$dbSources = array(‘dbcollection1′, ‘dbcollection2′);

/** Go to log in prompt */
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, GSA_PATH . ‘/EnterpriseController’);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch,CURLOPT_COOKIEJAR, dirname(__FILE__).‘/cookie.txt’);
curl_exec($ch);

/** Authenticate */
curl_setopt($ch, CURLOPT_URL, GSA_PATH . ‘/EnterpriseController’);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS,‘actionType=authenticateUser&userName=’ . GSA_USERNAME . ‘&password=’ . GSA_PASSWORD);
curl_exec($ch);

/** Loop through and trigger db sync for each collection in $dbSources */
if(is_array($dbSources)) {
foreach(
$dbSources as $source) {
curl_setopt($ch, CURLOPT_URL, GSA_PATH . ‘/EnterpriseController?actionType=syncDatabase&entryName=’ . $source);
curl_setopt($ch, CURLOPT_POST, false);
curl_exec($ch);
}
}

/** Close cURL connection */
curl_close($ch);

?>
Feedback and suggestions are appreciated… Enjoy!

Pagination With MSSQL Server Made Simple(r)

Tuesday, August 28th, 2007

First a Brief Overview of SQL Server 2005 Paging Headaches.

If you have ever found yourself working in a web development environment backed by SQL Server you undoubtedly have adapted a hatred for pagination. This hatred is only further fueled by knowing how easy it is with MySQL with the aid of the LIMIT operator. Prior to SQL Server 2005 developers were left with unintuitive and tedious stored procedures that would create temp tables prior to serving the desired results.

Now let’s look back at the title of this post “Pagination With MSSQL Server Made Simple(r)“… MSSQL 2005 doesn’t offer an operator with the equivalent of MySQL’s LIMIT, but I’ll show you the next best thing.

Using Straight SQL you can make use of the ROW_Number() function as described below.

SELECT Title, Description, User
FROM (SELECT ROW_NUMBER() OVER (ORDER BY created DESC)
AS Row, Title, Description, User FROM Blog)
AS BlogLimited
WHERE Row >= 6 AND Row <= 12

This can be thrown into an easier to use Stored Procedure.

CREATE PROCEDURE usp.BrowseBlog@PageNumber INT,@ResultsPerPage INTAS

BEGIN

WITH BlogEntries AS (SELECT ROW_NUMBER() OVER (ORDER BY created DESC)AS Row, Title, Description, UserFROM Blog)

SELECT Title, Description, UserFROM BlogEntriesWHERE Row between

(@PageNumber - 1) * @ResultsPerPage + 1 and @PageNumber*@ResultsPerPage

END 

Hopefully this will make your lives a little easier and reduce some of that stress :)

Ruby On Rails vs. PHP (Video)

Saturday, August 25th, 2007

Rails Envy, a blog created by two Ruby on Rails programmers from Orlando have just released an excellent spin-off of the Mac vs. PC commercials. In the spoof, they have created Ruby on Rails vs. PHP.

I haven’t dipped into Ruby on Rails yet but I have been known to walk around with my CakePHP shirt.

Ruby on Rails vs Java - RailsEnvy.com Commerical
Ruby on Rails vs PHP - RailsEnvy.com Commercial #2
Ruby on Rails vs PHP - RailsEnvy.com Commercial #3
Ruby on Rails vs PHP - RailsEnvy.com Commercial #4
Ruby on Rails vs .NET - RailsEnvy.com Commercial #5
Ruby on Rails vs PHP - RailsEnvy.com Commercial #6