Jump to content

MYSQL Server has gone away - Trying to load resources from another server


zgjonbalaj
 Share

Recommended Posts

Issue:

I get a MySQL server has gone away error at the end of the page, debug is true.

Setup:

The page template that this error occurs on connects to a Citrix Sharefile system and pulls all the files and folders for that user upon login using the Citrix PHP API. The delay in getting all these assets is long but the client is ok with that. I was hoping to find a way where I can have PW load the page and then begin loading the resources without throwing this error. 

Here is the page step by step process ( find the page source at the bottom of this post ):

- Require sharefile api resources (php include)

- If user posted login information through $_POST login the user and set necessary session variables

- display doc header

- begin displaying content elements on the page such as h1, p's etc

- connect to sharefile using authenticated user and pull all data from share file and output

- display footer & necessary script

Error:

Error: Exception: SQLSTATE[HY000]: General error: 2006 MySQL server has gone away (in /nfs/c11/h05/mnt/204835/domains/longpointcapital.com/html/wire/core/PageFinder.php line 297)

#0 [internal function]: PageFinder->___find(Object(Selectors), Array)
#1 /nfs/c11/h05/mnt/204835/domains/longpointcapital.com/html/wire/core/Wire.php(387): call_user_func_array(Array, Array)
#2 /nfs/c11/h05/mnt/204835/domains/longpointcapital.com/html/wire/core/Wire.php(325): Wire->runHooks('find', Array)
#3 /nfs/c11/h05/mnt/204835/domains/longpointcapital.com/html/wire/core/Pages.php(206): Wire->__call('find', Array)
#4 /nfs/c11/h05/mnt/204835/domains/longpointcapital.com/html/wire/core/Pages.php(206): PageFinder->find(Object(Selectors), Array)
#5 [internal function]: Pages->___find('parent_id=1, te...', Array)
#6 /nfs/c11/h05/mnt/204835/domains/longpointcapital.com/html/wire/core/Wire.php(387): call_user_func_array(Array, Array)
#7 /nfs/c11/h05/mnt/204835/domains/longpointcapital.com/html/wire/core/Wire.php(325): Wire->runHooks('find', A

<?

ini_set('mysql.connect_timeout', 1200);

// Start Session (PW Already Does This)
session_start();

// ShareFile API
require_once("_includes/sharefile-api.inc");

// Destroy Session After Inactivity
if (isset($_SESSION['LAST_ACTIVITY']) && (time() - $_SESSION['LAST_ACTIVITY'] > 600)) {
  unset($_SESSION['sharefile']);
}

// Update Session
$_SESSION['LAST_ACTIVITY'] = time();

// Enable ProcessWire Debugging
$config->debug = true;

// Logout
if (isset($input->post->logout)) {
  unset($_SESSION['sharefile']);
}

// CSRF Protection
$tokenName  = $this->session->CSRF->getTokenName();
$tokenValue = $this->session->CSRF->getTokenValue();
$loggedIn   = false;
$token      = null;

// Include Login Form Processor
if ($input->post->email && !$loggedin) {
	require("_includes/sharefile-form.inc");
}

// Check if user athenticated
if (isset($_SESSION['sharefile'])) {
	$loggedIn   = true;
	$token      = $_SESSION['sharefile'];
}

// Download File
if (isset($input->get->download)) {
	require("_includes/sharefile-download.inc");
}

function iterateObject($token, $object) {
	$object = get_children($token, $object);
	if ($object["odata.count"] >= 1) {
		foreach ($object['value'] as $child) {
			# Create container
			if (strpos($child['odata.metadata'], "Folder@Element") !== false) {
				echo "<div class='col-xs-12 folder-container'>
								<div class='folder'>";
				echo "		<span class='glyphicon glyphicon-folder-close'></span><span class='name'>" . $child['Name'] . "</span>";
									iterateObject($token, $child['Id']);
				echo "	</div>
							</div>";
			} else {
				echo "<div class='file'>
								<a target='' class='name' href='/investor-login/?download={$child['Id']}&name={$child['Name']}'><span class='glyphicon glyphicon-file'></span> "
									. $child['Name'] .
								"</a> -- <span class='size'>" . $child['FileSizeInKB'] . "KB</span>
							</div>";
			}
		}
	}
}

// Include Doc Header
require("_includes/doc-header.inc");

?>
	<body class="<?= $page->name ?>">

		<div class="clearfix oc-container oc-left oc-js">
			<div class="oc-overlay oc-js"></div>

			<!-- Include Common Header -->
			<? require("_includes/header.inc"); ?>

			<section class="container">

				<div class="row">
					<? if ($formSubmitted || $loggedIn && $failedAuth != true): ?>
						<? if ($loggedIn): ?>
						<div class="col-xs-12 col-sm-7 col-md-8 left-column investor-portal">
							<h1>Welcome</h1>
							<p><p>If you have any questions regarding your account, please contact our Office Administrator (<a href="#">#</a>), for more information.</p></p>

							<div class="row">
								<?= iterateObject($token, "allshared") ?>
							</div>

						</div>

						<div class="col-xs-12 col-sm-5 col-md-4 sidebar-column">
							<form class="logout-form" action="" method="post">
								<button id="logout" name="logout" type="submit" class="btn btn-default btn-logout">Logout</button>
							</form>
						</div>
						<? else: ?>

						<div class="col-xs-12 col-sm-7 col-md-8">
							<?= $formOutput ?>
						</div>
						<? require("_includes/sharefile-loginform.inc") ?>

						<? endif ?>
					<? else: ?>
						<div class="col-xs-12 col-sm-7 col-md-8">

							<?= $page->body ?>
						</div>

						<? require("_includes/sharefile-loginform.inc") ?>

					<? endif ?>
				</div>

			</section>

			<!-- Footer -->
			<? require("_includes/footer.inc"); ?>

			<script>

					$(document).ready(function() {

						$(".folder span.glyphicon").click(function(event) {

							var container = $(this).parent('.folder');
							var files     = container.children('.file, .folder-container');

							$(this).stop().toggleClass('glyphicon-folder-close glyphicon-folder-open');
							files.stop().toggle();

						});
					});

			</script>

		</div>
		<!-- End Off Canvas -->
	</body>
</html>
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...