'', 'message' => '')) * @param string $path (directory path for file) * @return boolean */ function createQueueItem($filename, $data = array(), $path = QUEUE_PATH) { $file = $path . DIRECTORY_SEPARATOR . $filename; if(!is_file($file)) { if ($data['phone'] && $data['message']) { $fp = fopen($file, 'w+'); fwrite($fp, $data['phone'] . PHP_EOL); fwrite($fp, $data['message'] . PHP_EOL); fclose($fp); } return (file_exists($file)) ? true : false; } else return false; } /** * Prepare file name * * @param string $path (directory path for file) * @param int $filenameLenght * * @return string */ function prepareFilename($path, $filenameLenght) { $filename = $path . DIRECTORY_SEPARATOR . generateRandomString($filenameLenght); while (file_exists($filename)) { $filename = $path . DIRECTORY_SEPARATOR . generateRandomString($filenameLenght); } return pathinfo($filename, PATHINFO_FILENAME); } /** * Generate random string for $length param (default value 8) * * @param int $length * @return string */ function generateRandomString($length = 8) { return substr(str_shuffle("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"), 0, $length); } /** * Return data array('phone', 'message') from file * * @param string $file filepath * @return array | false */ function parseFileData($file) { $data = file($file); $phone = trim($data[0]); unset($data[0]); $message = trim(implode(' ',$data)); return ($phone && $message) ? array('phone' => $phone, 'message' => $message) : false; } /** * Get queue count * @return int */ function getQueueCount() { return count(glob(QUEUE_PATH . DIRECTORY_SEPARATOR .'*')); } ?>