Showing posts with label error. Show all posts
Showing posts with label error. Show all posts

Friday 6 August 2021

How to resolve max execution time error in drupal ?

When you found error regarding 'max_execution_time' exceed, then you can follow steps for resolve this error:


Steps: 

You can put the below given code in drupal 8 index.php file.

ini_set('max_execution_time', 120); //for 120 seconds

ini_set('max_execution_time', 0); //for infinite process

OR

You can add below given code in settings.php file. (sites/default/settings.php)

ini_set('max_execution_time', 120); //for 120 seconds

ini_set('max_execution_time', 0); //for infinite process


Both will work for resolve that error.


Note: If have any suggestions or issue regarding 'How to resolve max execution time error in drupal ?' then you can ask by comments. 

 

Saturday 27 June 2020

How to check log error messages in Drupal 8?

As we know about log messages in Drupal, Log messages are our project related, every user related track (error, notice, warning, failure, PHP issue). In our Drupal we can check that track with URL '/admin/reports/dblog'.



And if we create a custom Module and we want to track every event of module, every time activity that we can write that code in this module.

Logs with an arbitrary level:
\Drupal::logger('module_name')->log($message); //When a module was installed

Normal but significant events:
\Drupal::logger('module_name')->notice($message); //Normals events, as cron execution

Exceptional occurrences:
\Drupal::logger('module_name')->warning($message); //exceptional cases not an error

Errors:
\Drupal::logger('module_name')->error($message); //error messages

And If we have requirement that we want to track this log error message by File
In that case we have a Drupal 8 module that we can install "File Log" module.

After configure, that file will be Create in root area Bydefault "site/default/files/logs".
I am going to share that module link here.

Note: If have any suggestions or issue regarding 'How to check log error messages in Drupal 8?' then you can ask by comments.  

Tuesday 7 January 2020

What is Namespace and Use keyword in drupal 8 module?

Namespace: Namespace is a way of Organizing your classes into folder and ensure that your class does not conflict with another class with the same name because the class can be same but namespace will be unique.

Use Keyword: use keyword allows you to use classes from another namespaces when you need them.

Drupal 8 generally use PHP classes instead of functions. Two classes can have same name in different namespace. Namespace is way of organize the classes into folders and subfolders and the namespace as the path of the file.

If you will try the same name file with the same name in same folder, you will get the fetal error. but if you want to create the same name file then you have to create subfolder and put there.

Get the example of namespaces with create module.

1. Start the custom module with create directory name like 'testing'.
2. Now create 'info.yml' file. That file tells Drupal that your module exist and have some content/information.

The filename should be the machine name of your module with .info.yml extension, like testing is our module name so here name will be 'testing.info.yml'.
File content:
    name: Testing
    description: A custom module to build our Drupal 8 module
    package: Custom
    type: module
    version: 1.0
    core: 8.x

   
3. Some modules have controllers, plugins, forms, templates, test all are in src folder. So now we will create the src required folder.
4. Now we need a page controller for show the content output with these simple steps:
  a. Create src folder.
  b. now create Controller folder under the src folder.
  c. within the Controller folder , create file with name of 'TestingController.php'.
In the 'TestingController.php' file we will print our short message for testing.

    /**
     * @file
     * Contains \Drupal\testing\Controller\TestingController.
     */
    namespace Drupal\testing\Controller;
    
    use Drupal\Core\Controller\ControllerBase;
    
    class TestingController extends ControllerBase {
      public function content() {
        return array(
          '#type' => 'markup',
          '#markup' => t('Hello, we are here for testing.'),
        );
      }
    } 
 

Here the namespace has been defined as Drupal\testing\Controller. We will not here use full folder structure like ->  Drupal\modules\testing\src\Controller

here modules\src is silent from namespace and Drupal automatically mapped with namespace src folder, so that we have to follow standard folder structure of modules.

If we have to use TestingController class in different namespace then we have to include with 'use keyword' as its namespace -> use Drupal\testing\Controller\TestingController;

TestingController is extending another class called ControllerBase. So for get the classes, include ControllerBase with use statement -> use Drupal\Core\Controller\ControllerBase;

If use statement are not included then PHP will looking for ControllerBase and gives error.
"So use statement allows you to use classes from another namespace."

5. Now we have to create important file with name of 'routing.yml'. here the name will be 'testing.routing.yml' that will create in custom module root.

    testing.content:
      path: '/testing'
      defaults:
        _controller: 'Drupal\testing\Controller\TestingController::content'
        _title: 'Hello Tester'
      requirements:
        _permission: 'access content'

       
so now enable the module and clear the cache then go with the path '/testing' and get the output form controller.
       

Note: What is Namespace and Use keyword in drupal 8 module?

How to resolve max execution time error in drupal ?

When you found error regarding 'max_execution_time' exceed, then you can follow steps for resolve this error: Steps:   You can put t...