Setting up a crontask

I followed this tutorial to backup my site vie a crontask in cpanel,
http://www.v-nessa.net/2007/01/03/cpanel-automated-backup-script
I thought everything was set up correctly, but get an email every night which says

Failed to open socket connection… Bailing out!

Heres the php script


<?php

// PHP script to allow periodic cPanel backups automatically.
// v-nessa.net
// Permissions on this file should be 600 
// Place outside your public_html
// Crontab:  30 3 * * * /usr/local/bin/php /home/username/cpanel_backup.php

// ********* Configuration *********

// Info required for cPanel access
$cpuser = "xxxxxx"; // Username used to login to CPanel
$cppass = "xxxxxx"; // Password used to login to CPanel
$domain = "www.xxxxxx.com/"; // Domain name where CPanel is run
$skin = "x3"; // Set to cPanel skin you use (script won't work if it doesn't match)

// Info required for FTP host
$ftpuser = "xxxxxxx"; // Username for FTP account
$ftppass = "xxxxxxx"; // Password for FTP account
$ftphost = "www.xxxxxxxx.com"; // Full hostname or IP address for FTP host
$ftpmode = "passiveftp"; // FTP mode ("ftp" for active, "passiveftp" for passive)
$ftpport = "21"; // FTP port, usually 21
$ftpdir = "/backups"; // Path to folder where backups should be stored off of FTP root. Folder must exist.

// Notification information
$notifyemail = "xxxxx@gmail.com"; // Email address to send results

// Secure or non-secure mode
$secure = 0; // Set to 1 for SSL (requires SSL support), otherwise will use standard HTTP

// Set to 1 to have web page result appear in your cron log
$debug = 1;

// *********** Don't Touch!! *********

if ($secure) {
   $url = "ssl://".$domain;
   $port = 2083;
} else {
   $url = $domain;
   $port = 2082;
}

$socket = fsockopen($url,$port);
if (!$socket) { echo "Failed to open socket connection... Bailing out!\
"; exit; }

// Encode authentication string
$authstr = $cpuser.":".$cppass;
$pass = base64_encode($authstr);

$params = "dest=$ftpmode&email=$notifyemail&server=$ftphost&user=$ftpuser&pass=$ftppass&port=$ftpport&rdir=$ftpdir&submit=Generate Backup";

// Make POST to cPanel
fputs($socket,"POST /frontend/".$skin."/backup/dofullbackup.html?".$params." HTTP/1.0\\r\
");
fputs($socket,"Host: $domain\\r\
");
fputs($socket,"Authorization: Basic $pass\\r\
");
fputs($socket,"Connection: Close\\r\
");
fputs($socket,"\\r\
");

// Grab response even if we don't do anything with it.
while (!feof($socket)) {
  $response = fgets($socket,4096);
  if ($debug) echo $response;
}

fclose($socket);

?>


Try to change this:


$socket = fsockopen($url,$port);
if (!$socket) { echo "Failed to open socket connection... Bailing out!\
"; exit; }

to this


$socket = fsockopen($url, $port, $errNo, $errStr);
if (!$socket) { echo "Failed to open socket connection ({$errStr}, {$errNo}) ... Bailing out!\
"; exit; }

run it again, and see what the output is. It should give you the reason it’s unable to connect.

im getting

Failed to open socket connection (php_network_getaddresses: getaddrinfo failed: Name or service not known, 0) … Bailing out!

what does that even mean?

It means the server can’t resolve the hostname of the server you want it to connect to. Are you you entered the host name (domain name) correctly?

I was kind of confused there, so I guess I was wrong,


$domain = "www.swedishsweetsandimports.com/"; // Domain name where CPanel is run
...
...
$ftphost = "www.swedishsweetsandimports.com"; // Full hostname or IP address for FTP host

Isn’;t that the domain, cause the sites at
that URL (http://www.swedishsweetsandimports.com/)
but the address I use to get to cpanel is
https://server73.web-hosting.com:2083/cpsess3541857546/frontend/x3/index.html

You need to change $domain to the domain cPanel is run on (server73.web-hosting.com, WITHOUT the :2083! ). Also set $secure = 1

thanks

guess it didnm’t work, cause heres the email,

Failed to open socket connection (php_network_getaddresses: getaddrinfo failed: No address associated with hostname, 0) … Bailing out!

The hostname I use for FTP is
swedishsweetsandimports.com
so


$ftphost = "swedishsweetsandimports.com"; // Full hostname or IP address for FTP host

is right?

Looks fine to me. If were you I’d contact the hoster to ask them why PHP doesn’t seem to be able to connect to that host. It sounds like a DNS error if you ask me.