<commit_before>'use strict';

var childProcess = require('child_process');
var config = require('../bin/config');
var requestQueue = require('./queue');
var logger = require('./logger');
var openedProcesses = 0;
var maxProcesses = config.maxProcesses || 1;

function responseTime(start) {
  var diff = process.hrtime(start);
  var ms = diff[0] * 1e3 + diff[1] * 1e-6;
  return Math.round(ms);
}

function reportOnProcesses() {
  logger.info('Currently ' + openedProcesses + ' processes running of a maximum of ' + maxProcesses + '.');
}

function getContent(url, callback) {
  var startAt = process.hrtime(),
      code = 200,
      phantom;

  function spawnLog(message, info, level) {
    info = info || {};
    if (!level && info.error) {
      level = 'error';
    }
    if (phantom) {
      info.pid = phantom.pid;
    }
    info.url = url;
    logger[level || 'info'](message, info);
  }

  openedProcesses++;
  spawnLog('Launching PhantomJS process to handle request...');
  reportOnProcesses();

  phantom = childProcess.execFile(
    __dirname + '/../node_modules/phantomjs/bin/phantomjs',
    [
      '--ignore-ssl-errors=' + config.ignoreSSLErrors,
      __dirname + '/phantom-server.js',
      url
    ],
    {
      timeout: config.phantomTimeout,
      killSignal: 'SIGKILL'
    },<commit_msg>Get PhantomJS binary path from module.<commit_after>'use strict';

var phantomJS = require('phantomjs');
var childProcess = require('child_process');
var config = require('../bin/config');
var requestQueue = require('./queue');
var logger = require('./logger');
var openedProcesses = 0;
var maxProcesses = config.maxProcesses || 1;

function responseTime(start) {
  var diff = process.hrtime(start);
  var ms = diff[0] * 1e3 + diff[1] * 1e-6;
  return Math.round(ms);
}

function reportOnProcesses() {
  logger.info('Currently ' + openedProcesses + ' processes running of a maximum of ' + maxProcesses + '.');
}

function getContent(url, callback) {
  var startAt = process.hrtime(),
      code = 200,
      phantom;

  function spawnLog(message, info, level) {
    info = info || {};
    if (!level && info.error) {
      level = 'error';
    }
    if (phantom) {
      info.pid = phantom.pid;
    }
    info.url = url;
    logger[level || 'info'](message, info);
  }

  openedProcesses++;
  spawnLog('Launching PhantomJS process to handle request...');
  reportOnProcesses();

  phantom = childProcess.execFile(
	  phantomJS.path,
    [
      '--ignore-ssl-errors=' + config.ignoreSSLErrors,
      __dirname + '/phantom-server.js',
      url
    ],
    {
      timeout: config.phantomTimeout,
      killSignal: 'SIGKILL'
    },
{'fraction_non_alphanumeric': 0.15174506828528073, 'fraction_numerical': 0.00834597875569044, 'mean_word_length': 3.199044585987261, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1147046', 'n_tokens_mistral': 875, 'n_tokens_neox': 831, 'n_words': 197}