Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • Saransaran/php-class-project
  • sibidharan/php-class-project
  • Madhan1024/php-class-project
  • GopiKrishnan/photogram
  • Mhd_khalid/php-class-project
  • At_muthu__/php-class-project
  • jaganbhaskar155/php-class-project
  • hariharanrd/php-class-project
  • jasper715/php-class-project
  • hanuRakesh/photogram-project-main
  • Yuvaraj21/photogram
  • ram_rogers/php-class-project
  • Hihelloboy/php-class-project
  • Nadarajan/php-class-project
  • srisanthosh156/php-class-project
  • Buvaneshwaran.k/php-class-project
  • umarfarooq07/php-class-project
  • Dhanaprakash/php-class-project
  • jashwanth142003/php-class-project
  • Esakkiraja/php-class-project
  • Boomi/php-class-project
  • Kishore2071/php-class-project
  • Ram123raj/php-class-project
  • aswinkumar27/php-class-project
  • dhilipdhilip9655/php-class-project
  • Manikandam143/php-class-project
  • VikramS/php-class-project
  • ArnoldSam/php-class-project
  • gowthamapandi0008/php-class-project
  • d.barath7639/php-class-project
  • shyalandran/php-class-project
  • kiruba_432/php-class-project
  • razakias001/php-class-project
  • kannan.b2745/php-class-project
  • sathish236tsk/php-class-project
  • rii/php-class-project
  • jonathajh4k/php-class-project
  • Neelagandan_G/php-class-project
  • Tholkappiar2003/php-class-project
  • kamaleshselvam75/php-class-project
  • devapriyan/php-class-project
  • sanojahamed/php-class-project
  • rizwankendo/php-class-project
  • senthamilselvan18000/php-class-project
  • rajeshd01/php-class-project
  • Florence/php-class-project
  • vishnu191299/php-class-project
  • Rakeshrakki/php-class-project
  • sanjay057/php-class-project
  • amarsanthoshsanthosh/photogram-project-cp
  • md_ashmar/php-class-project
  • k.nandhishwaran777k/php-class-project
52 results
Show changes
Showing
with 380 additions and 0 deletions
<?php
namespace PhpAmqpLib\Connection\Heartbeat;
use PhpAmqpLib\Connection\AbstractConnection;
use PhpAmqpLib\Exception\AMQPRuntimeException;
/**
* Manages pcntl-based heartbeat sending for a {@link AbstractConnection}.
*/
abstract class AbstractSignalHeartbeatSender
{
/**
* @var AbstractConnection|null
*/
protected $connection;
/**
* @param AbstractConnection $connection
* @throws AMQPRuntimeException
*/
public function __construct(AbstractConnection $connection)
{
if (!$this->isSupported()) {
throw new AMQPRuntimeException('Signal-based heartbeat sender is unsupported');
}
$this->connection = $connection;
}
public function __destruct()
{
$this->unregister();
}
/**
* @return bool
*/
protected function isSupported(): bool
{
return extension_loaded('pcntl')
&& function_exists('pcntl_async_signals')
&& (defined('AMQP_WITHOUT_SIGNALS') ? !AMQP_WITHOUT_SIGNALS : true);
}
/**
* Starts the heartbeats
*/
abstract public function register(): void;
/**
* Stops the heartbeats.
*/
abstract public function unregister(): void;
/**
* Handles the heartbeat when a signal interrupt is received
*
* @param int $interval
*/
protected function handleSignal(int $interval): void
{
if (!$this->connection) {
return;
}
if (!$this->connection->isConnected()) {
$this->unregister();
return;
}
if ($this->connection->isWriting()) {
return;
}
if (time() > ($this->connection->getLastActivity() + $interval)) {
$this->connection->checkHeartBeat();
}
}
}
<?php
namespace PhpAmqpLib\Connection\Heartbeat;
use PhpAmqpLib\Exception\AMQPRuntimeException;
/**
* @see AbstractSignalHeartbeatSender
*
* This version of a signal based heartbeat sendler relies on using SIGALRM and uses the OS to trigger an alarm
* after a given time.
*/
final class PCNTLHeartbeatSender extends AbstractSignalHeartbeatSender
{
public function register(): void
{
if (!$this->connection) {
throw new AMQPRuntimeException('Unable to re-register heartbeat sender');
}
if (!$this->connection->isConnected()) {
throw new AMQPRuntimeException('Unable to register heartbeat sender, connection is not active');
}
$timeout = $this->connection->getHeartbeat();
if ($timeout > 0) {
$interval = (int)ceil($timeout / 2);
pcntl_async_signals(true);
$this->registerListener($interval);
pcntl_alarm($interval);
}
}
public function unregister(): void
{
$this->connection = null;
// restore default signal handler
pcntl_signal(SIGALRM, SIG_IGN);
}
private function registerListener(int $interval): void
{
pcntl_signal(SIGALRM, function () use ($interval) {
$this->handleSignal($interval);
if ($this->connection) {
pcntl_alarm($interval);
}
}, true);
}
}
<?php
namespace PhpAmqpLib\Connection\Heartbeat;
use PhpAmqpLib\Connection\AbstractConnection;
use PhpAmqpLib\Exception\AMQPRuntimeException;
/**
* @see AbstractSignalHeartbeatSender
* @since 3.2.0
*
* This version of a signal based heartbeat sender allows using any signal number. It forks the current process
* to create a child process that periodically sends a signal to the parent process.
* The default signal used is SIGUSR1
*/
final class SIGHeartbeatSender extends AbstractSignalHeartbeatSender
{
/**
* @var int the UNIX signal to be used for managing heartbeats
*/
private $signal;
/**
* @var int|null the PID (process ID) of the child process sending regular signals to manage heartbeats
*/
private $childPid;
/**
* @param AbstractConnection $connection
* @param int $signal
* @throws AMQPRuntimeException
*/
public function __construct(AbstractConnection $connection, int $signal = SIGUSR1)
{
parent::__construct($connection);
$this->signal = $signal;
}
public function register(): void
{
if (!$this->connection) {
throw new AMQPRuntimeException('Unable to re-register heartbeat sender');
}
if (!$this->connection->isConnected()) {
throw new AMQPRuntimeException('Unable to register heartbeat sender, connection is not active');
}
$timeout = $this->connection->getHeartbeat();
if ($timeout > 0) {
$interval = (int)ceil($timeout / 2);
$this->registerListener($interval);
}
}
public function unregister(): void
{
$this->connection = null;
// restore default signal handler
pcntl_signal($this->signal, SIG_IGN);
if ($this->childPid > 0) {
posix_kill($this->childPid, SIGKILL);
}
$this->childPid = null;
}
private function registerListener(int $interval): void
{
pcntl_async_signals(true);
$this->periodicAlarm($interval);
pcntl_signal($this->signal, function () use ($interval) {
$this->handleSignal($interval);
});
}
/**
* Forks the current process to create a child process that will send periodic signals to the parent
*
* @param int $interval
*/
private function periodicAlarm(int $interval): void
{
$parent = getmypid();
$pid = pcntl_fork();
if(!$pid) {
while (true){
sleep($interval);
posix_kill($parent, $this->signal);
}
} else {
$this->childPid = $pid;
}
}
}
<?php
namespace PhpAmqpLib\Exception;
class AMQPBasicCancelException extends \Exception implements AMQPExceptionInterface
{
/**
* @var string
* @internal Use getter getConsumerTag()
*/
public $consumerTag;
/**
* @param string $consumerTag
*/
public function __construct($consumerTag)
{
parent::__construct('Channel was canceled');
$this->consumerTag = $consumerTag;
}
/**
* @return string
*/
public function getConsumerTag()
{
return $this->consumerTag;
}
}
<?php
namespace PhpAmqpLib\Exception;
class AMQPChannelClosedException extends AMQPRuntimeException
{
}
<?php
namespace PhpAmqpLib\Exception;
class AMQPConnectionBlockedException extends AMQPRuntimeException
{
public function __construct($message = '', $code = 0, $previous = null)
{
if (empty($message)) {
$message = 'Connection is blocked due to low resources';
}
parent::__construct($message, $code, $previous);
}
}
<?php
namespace PhpAmqpLib\Exception;
/**
* When connection was closed by server, proxy or some tunnel due to timeout or network issue.
*/
class AMQPConnectionClosedException extends AMQPRuntimeException
{
}
<?php
namespace PhpAmqpLib\Exception;
class AMQPDataReadException extends AMQPRuntimeException
{
}
<?php
namespace PhpAmqpLib\Exception;
class AMQPEmptyDeliveryTagException extends AMQPRuntimeException
{
}
<?php
namespace PhpAmqpLib\Exception;
interface AMQPExceptionInterface
{
}
<?php
namespace PhpAmqpLib\Exception;
class AMQPHeartbeatMissedException extends AMQPConnectionClosedException
{
}
<?php
namespace PhpAmqpLib\Exception;
class AMQPIOException extends \Exception implements AMQPExceptionInterface
{
}
<?php
namespace PhpAmqpLib\Exception;
class AMQPIOWaitException extends AMQPRuntimeException
{
}
<?php
namespace PhpAmqpLib\Exception;
class AMQPInvalidArgumentException extends \RuntimeException implements AMQPExceptionInterface
{
}
<?php
namespace PhpAmqpLib\Exception;
class AMQPInvalidFrameException extends AMQPRuntimeException
{
}
<?php
namespace PhpAmqpLib\Exception;
class AMQPLogicException extends \LogicException implements AMQPExceptionInterface
{
}
<?php
namespace PhpAmqpLib\Exception;
/**
* Used mostly in non-blocking methods when no data is ready for processing.
*/
class AMQPNoDataException extends AMQPRuntimeException
{
}
<?php
namespace PhpAmqpLib\Exception;
class AMQPNotImplementedException extends AMQPRuntimeException
{
}
<?php
namespace PhpAmqpLib\Exception;
class AMQPOutOfBoundsException extends \OutOfBoundsException implements AMQPExceptionInterface
{
}
<?php
namespace PhpAmqpLib\Exception;
class AMQPOutOfRangeException extends \OutOfRangeException implements AMQPExceptionInterface
{
}