You are here:  » Cron Jobs and Magic Parser


Cron Jobs and Magic Parser

Submitted by crounauer on Tue, 2006-10-03 14:42 in

Hi David,

Trying to set up a Cron Job for one of my scripts..

<?php
include("http://www.virtualhotels.net/includes/mysql_connect.php");
include("http://www.virtualhotels.net/includes/magicparser.php");
// Flag variable for sive status
$live = TRUE;
// Parse the countries start
// Create a global array
$countries = array();
function CountryCount($country)
  {
  global $countries;
  global $country_code;
  $countries[$country["COUNTRY_NAME"]] = $country["COUNTRY_CODE"];
  }
$country_url = "http://xml.xxxx_ctry.php3";
MagicParser_parse($country_url,"CountryCount","xml|CTRY_LIST/COUNTRY/");
if ($live)
  {
  echo "<b>Country Code Array</b><br>";
  //print_r($countries);
  echo "<br><br><b>Countries Parsed Succesfully!</b>";
  }
// Parse the countries end
// Parse and the regions start
// create a global array
$regions = array();
function myRegionHandler($region)
  {
  global $regions;
  global $region_code;
  global $country_code;
  $regions[$region["REGION_DESCRIPTION"]] = $region["REGION_CODE"];
  }
foreach($countries as $country_code)
  {
  $region_url = "http://xmlxxxxxregion.php3?ctry=".$country_code."";
  MagicParser_parse($region_url,"myRegionHandler","xml|REGION_LIST/REGION/");
  //sleep(5);
  }
if ($live)
  {
  echo "<br><br><b>Regions Code Array</b><br>";
  //print_r($regions);
  echo "<br><br><b>Regions Parsed Succesfully!</b>";
  }
// Parse and the regions end
// Parse and Download the hotels start
function myHotelHandler($hotel)
  {
  global $regions;
  global $region_code;
  global $countries;
  global $country_code;
  $sql_one = "REPLACE hotels (hotel_id,region_id,name,star,address,city,postcode,description,url,image,geo_code_long,geo_code_lat)
  VALUES (
  '".mysql_real_escape_string($hotel["HOTEL_REF"])."',
  '".mysql_real_escape_string($region_code)."',
  '".mysql_real_escape_string($hotel["HOTEL_NAME"])."',
  '".mysql_real_escape_string($hotel["HOTEL_STAR"])."',
  '".mysql_real_escape_string($hotel["HOTEL_ADDRESS"])."',
  '".mysql_real_escape_string($hotel["HOTEL_CITY"])."',
  '".mysql_real_escape_string($hotel["HOTEL_PCODE"])."',
  '".mysql_real_escape_string($hotel["HOTEL_DESCRIPTION"])."',
  '".mysql_real_escape_string($hotel["HOTEL_LINK"])."',
  '".mysql_real_escape_string($hotel["IMAGES/URL"])."',
  '".mysql_real_escape_string($hotel["GEO_CODE/LONG"])."',
  '".mysql_real_escape_string($hotel["GEO_CODE/LAT"])."'
  )";
  mysql_query($sql_one);
  }
if ($live)
  {
  echo "<br><br><b>Region Data Inserted!</b>";
  }
// need to get all regions from all the countries
foreach($countries as $country_code)
  {
    foreach($regions as $region_code)
      {
      $hotel_url = "http://xml.xxxx&ctry=".$country_code."&region=".$region_code."";
      MagicParser_parse($hotel_url,"myHotelHandler","xml|HOTEL_SEARCH/HOTEL/");
      sleep(2);
      }
  }
// Parse and Download the hotels end
?>

giving me an error of "call to undefined function MagicParser_parse() on line 17, which is

MagicParser_parse($country_url,"CountryCount","xml|CTRY_LIST/COUNTRY/");

I think this is because it needs an absolute location, can this be sorted?

Submitted by support on Tue, 2006-10-03 15:09

Hi Michael,

This code at the top of your script isn't valid:

include("http://www.virtualhotels.net/includes/mysql_connect.php");
include("http://www.virtualhotels.net/includes/magicparser.php");

You can't include a PHP from a URL because it will have been parsed, and all you will get back is an empty file. You will need to know the local path's to the includes, which is probably just includes/, so you need to use something like this:

include("includes/mysql_connect.php");
include("includes/magicparser.php");

...just as you would in a normal script.

Cheers,
David.

Submitted by crounauer on Wed, 2006-10-04 11:17

Hi David,

Yes, I am aware that for a "normal" php that script that the locations aren't valid, but if I dont make them absolute, I get an "open base restrictions" error. It is something I have come accross before and rectified it previously by using absolute locations.

Thanks again for your help.

Regards,
Simon

Submitted by support on Wed, 2006-10-04 19:00

My apologies, Simon - I missed your post this morning.....

Have you been able to get it working with absolute paths yet or is it still not able to find MagicParser.php?

Cheers,
David.

Submitted by adan on Thu, 2007-03-22 15:05

When using absolute paths, use realpath($_SERVER['DOCUMENT_ROOT']) to get a path to your root web directory (eg. /home/youruser/yourdomain ) that will always work.

It's taken me over a year to work this out, so I hope others will find it useful.

software reviews