<?php if (!defined('VB_ENTRY')) die('Access denied.'); class vB_Library_Worker extends vB_Library { protected $my_url_prefix = ''; protected $timeout = 3; protected function __construct() { $options = vB::getDatastore()->getValue('options'); if (!empty($options['frontendurl'])) { $this->my_url_prefix = $options['frontendurl'] . "/worker/"; } if (!empty($options['fcm_worker_remote_timeout']) AND $options['fcm_worker_remote_timeout'] > 0) { $this->timeout = $options['fcm_worker_remote_timeout']; } return true; } public function testWorkerConnection() { $check = $this->callWorker("test"); $decoded = array( 'error' => "unknown error", ); if (!empty($check['body'])) { $decoded = json_decode($check['body'], true); } return $decoded; } public function callWorker($action, $postData = array()) { if (empty($this->my_url_prefix)) { return array( 'error' => "missing_my_url", ); } if (empty($action)) { return array( 'error' => "missing_action", ); } $action = ltrim($action, '/'); $url = $this->my_url_prefix . $action; $httpHeaders = array( 'Content-Type: application/x-www-form-urlencoded', ); $postFields = http_build_query($postData); $vurl = vB::getUrlLoader(true); $vurl->setOption(vB_Utility_Url::CLOSECONNECTION, 1); $vurl->setOption(vB_Utility_Url::HTTPHEADER, $httpHeaders); $vurl->setOption(vB_Utility_Url::HEADER, 1); $vurl->setOption(vB_Utility_Url::TIMEOUT, $this->timeout); $result = $vurl->post($url, $postFields); return $result; } } 