Page : | [ 1 ] | [ 2 ] | [ 3 ] | [ 4 ] | [ 5 ] |
start.php gets called from cron on a regular interval. In my case I'm calling it every 13 days since the trial period at ACR Cloud is 14 days.
It's pretty simple, just pass it one argument which specifies which service you want to deal with.
i.e.
start.php acrcloud
The idea is to be able to handle multiple services by defining them in the config and creating a class to handle it. Currently I just have ACR Cloud in mind.
Here's what start.php looks like:
#!/usr/bin/php -q
<?php
include __DIR__ . '/inc/config.php';
if (count($argv) == 2){
if (array_key_exists($argv[1], $services)){
$service = false;
if ($services[$argv[1]] == SERVICEID_ACRCLOUD){
$service = new ACRCloud();
}
if ($service){
$ok = $service->start();
if ($ok){
$service->signUp();
}
}
} else {
echo "\nPlease enter a proper service name (i.e. 'start.php acrcloud')\n";
}
} else {
echo "\nPlease enter a proper service name (i.e. 'start.php acrcloud')\n";
}
?>
The config file that's being included is very simple and just sets up some auto loading and also a define for acrcloud. It also includes some stuff from the Zend framework for handling mail.
Here it is :
<?php
define('BASEDIR', dirname(dirname(__FILE__)));
$path = BASEDIR . '/inc/classes/';
set_include_path(get_include_path() . PATH_SEPARATOR . $path);
include (BASEDIR . '/inc/classes/Zend/Mail/Message.php');
function auto_loader($class) {
include BASEDIR . '/inc/classes/' . $class . '.class.php';
}
spl_autoload_register('auto_loader');
define ('DB_HOST', "localhost");
define ('DB_USER', "yourDatabaseUser");
define ('DB_PASS', "yourDatabasePassword");
define ('DB_DATABASE', "catchall");
define ('SERVICEID_ACRCLOUD', 1);
$services = array();
$services['acrcloud'] = SERVICEID_ACRCLOUD;
?>
Start.php will just instantiate an object for the particular service needed and call a method called "start" which creates an account in our database and populates it with some random data to use when signing up. It then calls the "signUp" method to actually do the work of signing up at ACR Cloud.
The database schema:
create database catchall;
create table service(
serviceId int unsigned not null primary key,
serviceName varchar(32) unique
);
insert into service (serviceId, serviceName) values (1, 'acrcloud');
create table meta(
metaId int unsigned not null primary key auto_increment,
dat text,
used tinyint not null default 0
);
create table account(
accountId int unsigned not null primary key auto_increment,
serviceId int unsigned,
email varchar(128),
inputData text,
signUpForm text,
htmlAfter text,
didSignUp tinyint unsigned not null default 0,
verifyLink text,
emailMessage text,
gotEmail tinyint unsigned not null default 0,
finished tinyint unsigned not null default 0,
success tinyint unsigned not null default 0,
results text
);
The META table just contains 1000 rows of data from a site calle Mockaroo that has some random data for city,country,phone,company,url,address,password. I use them one at a time and mark them as being "used" afterwards.
On the next page is what's in ACRCloud.class.php
(Page 2 of 5) | ||