2

I have a php script that does some querying and book keeping of drupal tables. How can I run this php script directly from the url? The script uses drupal functions so I guess it should be aware of the API.

When I go to mysite.com/script.php I would like this file to run...

Is there any includes that I can add and then run the script so that it is drupal aware and at the same time, does not need to go through all the view/node/block etc? Basically I do not want to add this page as a PHP block data into one of the nodes, I would like to run in directly from the URL.

1
  • Better to just wrap the PHP script as a Drupal module. Basically add a .info metadata file and put the PHP code in the .module file. More info: drupal.org/developing/modules – David Thomas Jun 12 '14 at 7:43
2

you should boot drupal on your file so that your file be aware of drupal functions,you can do this by : YOUR_DRUPAL_ROOT= root of your drupal,here my drupal root was crawler.alexa.com. and require bootstrap.inc of your drupal. and then boot drupal compeletly. here is my example :

define('DRUPAL_ROOT', '../crawler.alexa.com');
require_once '../crawler.alexa.com/includes/bootstrap.inc';
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
0
1

I would put create a module, and use hook_menu.

function mymodule_menu() {
    $items['custom/script'] = array(
      'page callback' => 'mymodule_custom_script_function',
    );
    return $items;
}

function mymodule_custom_script_function() {
    // put the code from your PHP script here
}
0

You have to change the configuration setting.

Just follow the link and you will have the solution.

https://github.com/perusio/drupal-with-nginx/issues/63

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.