From 957c09f237c8399cebdb5babeaac077506e7d364 Mon Sep 17 00:00:00 2001 From: Aaron Parecki Date: Sat, 6 Feb 2016 12:44:52 -0800 Subject: [PATCH] attempt to disconnect and reconnect from the database between jobs --- lib/Telegraph/Webmention.php | 7 ++++++- lib/helpers.php | 8 +++++--- public/index.php | 2 ++ 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/lib/Telegraph/Webmention.php b/lib/Telegraph/Webmention.php index 392edb7..cc24f5a 100644 --- a/lib/Telegraph/Webmention.php +++ b/lib/Telegraph/Webmention.php @@ -37,6 +37,8 @@ class Webmention { } public static function send($id, $client=false, $http=false) { + initdb(); + $webmention = ORM::for_table('webmentions')->where('id', $id)->find_one(); if(!$webmention) { echo 'Webmention '.$id.' was not found'."\n"; @@ -98,7 +100,10 @@ class Webmention { $webmention->save(); - return self::updateStatus($webmention, $response['code'], $status, $response['body']); + $result = self::updateStatus($webmention, $response['code'], $status, $response['body']); + $pdo = ORM::get_db(); + $pdo = null; + return $result; } } diff --git a/lib/helpers.php b/lib/helpers.php index 10002da..f084b85 100644 --- a/lib/helpers.php +++ b/lib/helpers.php @@ -7,9 +7,11 @@ if(array_key_exists('ENV', $_ENV)) { require(dirname(__FILE__).'/../config.php'); } -ORM::configure('mysql:host=' . Config::$db['host'] . ';dbname=' . Config::$db['database']); -ORM::configure('username', Config::$db['username']); -ORM::configure('password', Config::$db['password']); +function initdb() { + ORM::configure('mysql:host=' . Config::$db['host'] . ';dbname=' . Config::$db['database']); + ORM::configure('username', Config::$db['username']); + ORM::configure('password', Config::$db['password']); +} function view($template, $data=[]) { global $templates; diff --git a/public/index.php b/public/index.php index ede0878..1d0a61f 100644 --- a/public/index.php +++ b/public/index.php @@ -2,6 +2,8 @@ chdir('..'); include('vendor/autoload.php'); +initdb(); + use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; $router = new League\Route\RouteCollection;