/** * (non-PHPdoc) * @see PAGI\CallSpool.ICallSpool::spool() */ public function spool(CallFile $call, $schedule = false) { $filename = tempnam($this->_tmpDir, 'PAGICallFile'); if ($filename === false) { throw new CallSpoolException('Could generate temporary filename'); } if (@file_put_contents($filename, $call->serialize()) === false) { @unlink($filename); throw new CallSpoolException('Error writing: ' . $filename); } if ($schedule !== false) { if (@touch($filename, $schedule) === false) { @unlink($filename); throw new CallSpoolException('Error scheduling: ' . $filename); } } $newFilename = implode(DIRECTORY_SEPARATOR, array($this->_spoolDir, 'outgoing', basename($filename))); if (@rename($filename, $newFilename) === false) { @unlink($filename); throw new CallSpoolException('Error spooling: ' . $newFilename); } return $newFilename; }
use PAGI\DialDescriptor\SIPDialDescriptor; use PAGI\DialDescriptor\DAHDIDialDescriptor; $dialDescriptor = new DAHDIDialDescriptor('1949890333', 1); $callFile = new CallFile($dialDescriptor); $callFile->setContext('campaign'); $callFile->setExtension('failed'); $callFile->setVariable('foo', 'bar'); $callFile->setPriority('1'); $callFile->setMaxRetries('0'); $callFile->setWaitTime(10); $callFile->setCallerId('some<123123>'); echo "Call file generated (DAHDI dial descriptor):\n"; echo $callFile->serialize(); echo "\n\n"; $dialDescriptor = new SIPDialDescriptor('24', 'example.com'); $callFile = new CallFile($dialDescriptor); $callFile->setContext('default'); $callFile->setExtension('777'); $callFile->setVariable('foo', 'bar'); $callFile->setPriority('1'); $callFile->setMaxRetries('0'); $callFile->setWaitTime(10); $callFile->setCallerId('some<123123>'); echo "Call file generated (SIP dial descriptor):\n"; echo $callFile->serialize(); echo "\n\n\n"; echo "Spooling generated SIP call\n"; $spool = CallSpoolImpl::getInstance(array('tmpDir' => '/tmp', 'spoolDir' => '/tmp/spoolExample')); $spool->spool($callFile); echo "Spooling generated SIP call to run in 30 seconds\n"; $spool->spool($callFile, time() + 30);