404

[ Avaa Bypassed ]




Upload:

Command:

elspacio@3.23.101.231: ~ $
<?php
/**
 * Copyright 2017 Google Inc. All Rights Reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

namespace Google\Cloud\Core\Batch;

/**
 * ConfigStorageInterface implementation with SystemV IPC shared memory.
 *
 * @experimental The experimental flag means that while we believe this method
 *      or class is ready for use, it may change before release in backwards-
 *      incompatible ways. Please use with caution, and test thoroughly when
 *      upgrading.
 */
class SysvConfigStorage implements ConfigStorageInterface
{
    const VAR_KEY = 1;

    const DEFAULT_SHM_SIZE = 200000;

    const DEFAULT_PERM = 0600;

    const DEFAULT_PROJECT = 'A';

    /* @var int */
    private $sysvKey;

    /* @var int */
    private $semid;

    /* @var int */
    private $shmSize;

    /* @var int */
    private $perm;

    /* @var string */
    private $project;

    /**
     * Prepare the key for semaphore and shared memory.
     */
    public function __construct()
    {
        $this->shmSize = intval(getenv('GOOGLE_CLOUD_BATCH_SHM_SIZE'));
        if ($this->shmSize === 0) {
            $this->shmSize = self::DEFAULT_SHM_SIZE;
        }
        $this->perm = octdec(getenv('GOOGLE_CLOUD_BATCH_PERM'));
        if ($this->perm === 0) {
            $this->perm = self::DEFAULT_PERM;
        }
        $this->project = getenv('GOOGLE_CLOUD_BATCH_PROJECT');
        if ($this->project === false) {
            $this->project = self::DEFAULT_PROJECT;
        }
        $this->sysvKey = ftok(__FILE__, $this->project);
        $this->semid = sem_get($this->sysvKey, 1, $this->perm, 1);
    }

    /**
     * Acquire a lock.
     *
     * @return bool
     */
    public function lock()
    {
        return sem_acquire($this->semid);
    }

    /**
     * Release a lock.
     *
     * @return bool
     */
    public function unlock()
    {
        return sem_release($this->semid);
    }

    /**
     * Save the given JobConfig.
     *
     * @param JobConfig $config A JobConfig to save.
     * @return bool
     * @throws \RuntimeException when failed to attach to the shared memory or serialization fails
     */
    public function save(JobConfig $config)
    {
        $shmid = shm_attach($this->sysvKey, $this->shmSize, $this->perm);
        if ($shmid === false) {
            throw new \RuntimeException(
                'Failed to attach to the shared memory'
            );
        }

        // If the variable write fails, clear the memory and re-raise the exception
        try {
            $result = shm_put_var($shmid, self::VAR_KEY, $config);
        } catch (\Exception $e) {
            $this->clear();
            throw new \RuntimeException($e->getMessage());
        } finally {
            shm_detach($shmid);
        }
        return $result;
    }

    /**
     * Load a JobConfig from the storage.
     *
     * @return JobConfig
     * @throws \RuntimeException when failed to attach to the shared memory or deserialization fails
     */
    public function load()
    {
        $shmid = shm_attach($this->sysvKey, $this->shmSize, $this->perm);
        if ($shmid === false) {
            throw new \RuntimeException(
                'Failed to attach to the shared memory'
            );
        }
        if (! shm_has_var($shmid, self::VAR_KEY)) {
            $result = new JobConfig();
        } else {
            $result = shm_get_var($shmid, self::VAR_KEY);
        }
        shm_detach($shmid);

        if ($result === false) {
            throw new \RuntimeException(
                'Failed to deserialize data from shared memory'
            );
        }
        return $result;
    }

    /**
     * Clear the JobConfig from storage.
     */
    public function clear()
    {
        $shmid = shm_attach($this->sysvKey, $this->shmSize, $this->perm);
        shm_remove_var($shmid, self::VAR_KEY);
    }

    /**
     * Serialize the object
     */
    public function __serialize()
    {
        $vars = get_object_vars($this);
        // As of PHP 8.0, "semid" is the unserializable object "SysvSemaphore"
        // @see https://github.com/googleapis/google-cloud-php/issues/3749
        unset($vars['semid']);
        return $vars;
    }
}

Filemanager

Name Type Size Permission Actions
BatchDaemon.php File 5.36 KB 0644
BatchDaemonTrait.php File 1.31 KB 0644
BatchJob.php File 6.01 KB 0644
BatchRunner.php File 6.17 KB 0644
BatchTrait.php File 6.45 KB 0644
ClosureSerializerInterface.php File 1.25 KB 0644
ConfigStorageInterface.php File 1.65 KB 0644
HandleFailureTrait.php File 3.01 KB 0644
InMemoryConfigStorage.php File 5.41 KB 0644
InterruptTrait.php File 1.89 KB 0644
JobConfig.php File 3.07 KB 0644
JobInterface.php File 1.55 KB 0644
JobTrait.php File 2.29 KB 0644
OpisClosureSerializer.php File 1.66 KB 0644
ProcessItemInterface.php File 1.42 KB 0644
QueueOverflowException.php File 1.12 KB 0644
Retry.php File 2.27 KB 0644
SerializableClientTrait.php File 3.12 KB 0644
SimpleJob.php File 2.31 KB 0644
SimpleJobTrait.php File 3.52 KB 0644
SysvConfigStorage.php File 4.61 KB 0644
SysvProcessor.php File 2.8 KB 0644