Trying to implement the integration with linkchecker, but I don't get it from docs. Can you help me, please?

  $options = array(
    'headers' => $headers,
    'method' => $link->method,
    'max_redirects' => 0,
    'blocking' => TRUE,
    'linkchecker_link' => $link, // Not the clean way, but the object is required.
  );

based on docs is may should be something like:

  $options = array(
    'headers' => $headers,
    'method' => $link->method,
    'max_redirects' => 0,
    'blocking' => TRUE,
    'linkchecker_link' => $link, // Not the clean way, but the object is required.
    'background_callback' => array(
      array(
        'function' => '_linkchecker_status_handling',
       ),
    );

But how can I tell the background process to pass two params and not only the responds object _linkchecker_status_handling($link, $response)? 'linkchecker_link' => $link need to be the first param and the httprl responds object the second param.

I'm guess I have no need for 'return' and 'printed' inside the 'background_callback' array.

Comments

mikeytown2’s picture

  $options = array(
    'headers' => $headers,
    'method' => $link->method,
    'max_redirects' => 0,
    'blocking' => TRUE,
    'background_callback' => array(
      array(
        'function' => '_linkchecker_status_handling',
       ),
      $link,
    );

This will call _linkchecker_status_handling($this, $link); where $this is the $request object from HTTPRL. By omitting return/printed this request will fireoff in a non-blocking manner. Something to be aware of is that non-blocking requests have no throttle; it's nearly impossible to throttle them. Shouldn't be a major concern as long as you adjust the global_connections option to be smaller as the number of non-blocking requests will be close to global_connections.

If I where you I would use callbacks at first then move on to background callbacks and finally non blocking background callbacks. Should make debugging simpler.

Start here:

  $options = array(
    'headers' => $headers,
    'method' => $link->method,
    'max_redirects' => 0,
    'blocking' => TRUE,
    'callback' => array(
      array(
        'function' => '_linkchecker_status_handling',
        'return' => '',
       ),
      $link,
    );
mikeytown2’s picture

@hass
I know we talked about SSL certs in an older issue (#1428474-4: redirect_code/redirect_url are arrays, not single values like core (expected)). I found 2 use cases in all of contrib (see #64866: Pluggable architecture for drupal_http_request() for reasons why I'm looking) that sends context to drupal_http_request():

Modules that use context (stream_context_create()) in drupal_http_request():
Acquia Network Connector in acquia_agent_stream_context_create()
Shorten URLs in _shorten_googl()
Both deal with SSL. Using this in Link Checker might be of interest.

http://php.net/context.ssl
Setting verify_peer to TRUE seem like a good idea for your module.

hass’s picture

The options should to be flipped... Is this possible or do I need to change the orger in linkchecker?

I try to check out the rest

mikeytown2’s picture

You want this correct?
_linkchecker_status_handling($link, $request);
I thought about making it an option but I decided against it as it's fairly complex as is. The request argument is always passed first.
_linkchecker_status_handling($request, $link);
So you need to change the order in link checker or have a function that will call _linkchecker_status_handling() with the correct parameters.

mikeytown2’s picture

Status: Active » Closed (works as designed)

Closing this issue as not a lot has happened. Reopen if needed.