I have a file parser.php

$url = 'http://site.kz';

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt ($ch , CURLOPT_USERAGENT , "Mozilla/5.0 ");
curl_setopt ($ch , CURLOPT_RETURNTRANSFER , 1 );
$link = curl_exec($ch);

so all contents of the site -site.kz is in $content variable. If i call this script http://site.kz/sites/all/themes/mytheme/parser.php -> it starts to grab this page, right?

How can i make available that variable $link in a page.tpl.php? If i make include ('parser.php') then everytime i F5 my page → parser is going to work (creates load to the server).


If you don't want your script to execute on each page load, you have to set up a cron job, either via hook_cron() or a separate job.

To make a variable available in a template file, you have to use a preprocess function of some sort.

With these two elements, you should be able to make your script work and be integrated with Drupal.

  • can u throw examples? Mar 1 '12 at 13:45
  • I could but don't have time, sorry. Could do it as a paid job though o_O. You'll find plenty of examples on d.o or many other places.
    – Countzero
    Mar 1 '12 at 15:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.