function read_url_write($url, $save_dir, $key) { if (empty($url) || empty($save_dir) || empty($key)) { return; } if (!is_dir($save_dir)) { mkdir($save_dir); } ini_set('memory_limit', '1000M'); $sum = 0; for ($m = 1; $m < 26; $m++) { $start = $sum; $end = $sum + 1000; $sum = $end; $count = 0; if (!is_file($save_dir . $start . '-' . $end)) { my_log("START {$start}-{$end}"); $handle = fopen("{$save_dir}{$start}-{$end}", 'wb'); for ($i = $start; $i < $end; $i++) { $url_temp = $url . '?id=' . $i . '&username=xinhuaxuanwen&password=456789'; $arr_str = @file_get_contents($url_temp); $arr_temp = json_decode($arr_str, true); if (@$arr_temp[$key]) { fwrite($handle, $arr_str . ','); $count++; } } my_log("HANDLE {$count}"); fclose($handle); my_log("ENDED {$start}-{$end}"); } } }
function reg_abstract(&$ret_url) { echo "<p>발표 정보를 등록합니다.</p>\n"; $id = get_valid_id($_REQUEST["id"]); $when = get_valid_time($_REQUEST["when"]); $t = strtotime($when); $ret_url = "reg_abstract?id=" . $id . "&date=" . date('Y-m-d', $t); $talk_data = get_talk_data_or_gen($t, $id); $talk_data["title"] = $_REQUEST["title"]; $talk_data["abstract"] = $_REQUEST["abstract"]; $result1 = put_talk_data($t, $id, $talk_data); $result2 = true; if ($_FILES["memo"]["type"] === "application/pdf") { echo "<p>메모를 등록합니다.</p>\n"; $memo_filename = gen_memo_filename($t, $id); $result2 = move_uploaded_file($_FILES["memo"]["tmp_name"], $memo_filename); if ($result2) { chmod($memo_filename, 0664); my_log(__FILE__, $memo_filename . " updated\n"); } else { my_log(__FILE__, $memo_filename . " update failed\n"); } } return $result1 && $result2; }
public function perform() { my_log('/data/log/cronJob/doJob.log', '456'); $time = $this->args['t']; $sets = $this->redis->getCronJob($time); my_log('/data/log/cronJob/doJob.log', $time); foreach ($sets as $row) { $job = unserialize($row); if (isset($job['m']) && isset($job['p']) && isset($job['c'])) { if (ParseCrontab::parse($job['p']) == true) { $msg = $this->makeCmd($job['m'], $job['c']); $res = $this->socket->send($msg); if (!$res) { $error = 'Cronjob ' . $time . ' ' . $row . ' send message error'; my_log('/data/log/cronJob/doJob.log', $error); } else { $error = 'Cronjob ' . $time . ' ' . $row . ' send message success'; my_log('/data/log/cronJob/doJob.log', $error); } } } else { $error = 'Cronjob ' . $time . ' ' . $row . ' format error'; my_log('/data/log/cronJob/doJob.log', $error); } } }
/** * listDir * Método para obter todo o conteúdo de um diretorio, e * que atendam ao critério indicado. * @package spoolga * @name listDir * @version 2.0 * @author Joao Paulo Bastos L. <jpbl.bastos at gmail dot com> * @param string $dir Diretorio a ser pesquisado * @param string $fileMatch Critério de seleção pode ser usados coringas como *-nfe.xml * @param boolean $retpath se true retorna o path completo dos arquivos se false so retorna o nome dos arquivos * @return mixed Matriz com os nome dos arquivos que atendem ao critério estabelecido ou false */ function listDir($dir, $fileMatch, $retpath = true) { if (trim($fileMatch) != '' && trim($dir) != '') { //passar o padrão para minúsculas $fileMatch = strtolower($fileMatch); //cria um array limpo $aName = array(); //guarda o diretorio atual $oldDir = getcwd() . DIRECTORY_SEPARATOR; //verifica se o parametro $dir define um diretorio real if (is_dir($dir)) { //mude para o novo diretorio chdir($dir); //pegue o diretorio $diretorio = getcwd() . DIRECTORY_SEPARATOR; if (strtolower($dir) != strtolower($diretorio)) { my_log("Motor Diz: OPS erro inesperado, Falha não há permissão de leitura no diretorio escolhido em " . date('Y-m-d H:i:s'), $logApp); return false; } //abra o diretório $ponteiro = opendir($diretorio); $x = 0; // monta os vetores com os itens encontrados na pasta while (false !== ($file = readdir($ponteiro))) { //procure se não for diretorio if ($file != "." && $file != "..") { if (!is_dir($file)) { $tfile = strtolower($file); //é um arquivo então //verifique se combina com o $fileMatch if (fnmatch($fileMatch, $tfile)) { if ($retpath) { $aName[$x] = $dir . $file; } else { $aName[$x] = $file; } $x++; } } //endif é diretorio } //endif é . ou .. } //endwhile closedir($ponteiro); //volte para o diretorio anterior chdir($oldDir); } //endif do teste se é um diretorio } //endif return $aName; }
function send_mail($mode, $from, $to, $subj, $msg) { $headers = 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/' . $mode . '; charset=UTF-8' . "\r\n"; $headers .= "From: =?UTF-8?B?" . base64_encode($from["name"]) . "?=" . " <" . $from["email"] . ">\r\n"; $subj = "=?UTF-8?B?" . base64_encode($subj) . "?="; if (mail(implode(",", $to), $subj, $msg, $headers)) { my_log(__FILE__, "Succeed to send mail\n"); } else { my_log(__FILE__, "Fail to send mail\n"); exit(1); } }
function my_onClose($serv, $fd, $from_id) { my_log("Worker#{$serv->worker_pid} Client[{$fd}@{$from_id}]: fd={$fd} is closed"); $buffer = G::getBuffer($fd); if ($buffer) { $buffer->clear(); } if ($serv->exist($fd)) { echo 'FD[' . $fd . '] exist' . PHP_EOL; } else { echo 'FD[' . $fd . '] not exist' . PHP_EOL; } }
function my_file_put_contents($filename, $data) { $is_new = !file_exists($filename); if (file_put_contents($filename, $data) === false) { my_log(__FILE__, "{$filename} cannot be written\n"); return false; } else { if ($is_new) { chmod($filename, 0664); } my_log(__FILE__, "{$filename} updated\n"); return true; } }
public function __construct() { parent::__construct(); $this->load->library('auth_lib'); if (!$this->auth_lib->is_valid_user()) { $email = $this->auth_lib->user()->email; $ip = $this->input->ip_address(); my_log("User `{$email}` tried to login from {$ip}"); $error_msg = 'You are not allowed to view this page.<br/> Contact Administrator.<br/> You can logout from <a href="' . base_url('logout') . '">here</a>'; show_error($error_msg, 403, 'Permission Denied'); } }
function get_member($id) { $members = get_all_members(); $members = array_filter($members, function ($member) use($id) { if ($id === $member["id"]) { return true; } else { return false; } }); if (sizeof($members) === 1) { return array_pop($members); } else { my_log(__FILE__, "Member ID is invalid\n"); exit(1); } }
public function run() { $time = date('H_i', $this->start); // for test //$time = '13_18'; $sets = $this->redis->getCronJob($time); if (!empty($sets)) { // if(count($sets)>0){ $res = $this->pushToQueue(array('t' => $time)); if (empty($res)) { $error = 'Cronjob ' . $time . ' push fail'; my_log('/data/log/cronJob/doJob.log', $error); } else { $error = 'Cronjob ' . $time . ' push ok, Id ' . $res; my_log('/data/log/cronJob/doJob.log', $error); } // } } }
function gen_commenter($speakers) { $all = array_map(function ($m) { return $m["id"]; }, get_all_members()); $listeners = array_filter($all, function ($id) use($speakers) { return !in_array($id, $speakers); }); if (count($speakers) * 3 > count($listeners)) { my_log(__FILE__, "Listeners are too less compared to speakers\n"); exit(1); } shuffle($listeners); $commenter_info = array(); foreach ($speakers as $speaker) { $commenter_info[$speaker] = array_slice($listeners, 0, 3); $listeners = array_slice($listeners, 3); } return $commenter_info; }
function my_onReceive(swoole_server $serv, $fd, $from_id, $data) { my_log("Worker#{$serv->worker_pid} Client[{$fd}@{$from_id}]: received: {$data}"); $cmd = trim($data); if ($cmd == "reload") { $serv->reload($serv); } elseif ($cmd == "task") { $task_id = $serv->task("hello world"); echo "Dispath AsyncTask: id={$task_id}\n"; } elseif ($cmd == "taskwait") { $result = $serv->taskwait("hello world", 2); echo "SyncTask: result={$result}\n"; } elseif ($cmd == "hellotask") { $serv->task("hellotask"); } elseif ($cmd == "close") { $serv->send($fd, "close connection\n"); $result = $serv->close($fd); } elseif ($cmd == "info") { $info = $serv->connection_info($fd); $serv->send($fd, 'Info: ' . var_export($info, true) . PHP_EOL); } elseif ($cmd == "stats") { $serv_stats = $serv->stats(); $serv->send($fd, 'Stats: ' . var_export($serv_stats, true) . PHP_EOL); } elseif ($cmd == "broadcast") { broadcast($serv, $fd, "hello from {$fd}\n"); } elseif ($cmd == "error") { hello_no_exists(); } elseif (substr($cmd, 0, 5) == "close") { $close_fd = substr($cmd, 6); $serv->close($close_fd); } elseif ($cmd == "shutdown") { $serv->shutdown(); } else { $ret = $serv->send($fd, 'Swoole: ' . $data, $from_id); //var_dump($ret); //$serv->close($fd); } //echo "Client:Data. fd=$fd|from_id=$from_id|data=$data"; //$serv->deltimer(800); //swoole_server_send($serv, $other_fd, "Server: $data", $other_from_id); }
/** Description: ; input: classname,$functionname,$errorcode, items return array */ function returnXML($arrArgs, $class_name, $function_name, $array_input, $obj = NULL) { $count = count($arrArgs); $user = $arrArgs[$count - 2]; if (strpos($obj->_MDB2->last_query, "sp_ServiceLogin") > 0) { my_log($user, 'INFO', $obj->_MDB2->last_query); } if ($obj->_MDB2_WRITE->last_query != "") { $kind = $class_name . "->" . $function_name; $detail = $obj->_MDB2_WRITE->last_query . " --> " . $error_code; my_log($user, 'ALL', $detail); } $result = "{urn:" . $class_name . "}" . $function_name . "Result"; $array = "{urn:" . $class_name . "}" . $function_name . "Array"; /*return new SOAP_Value('return', $result, array( "error_code" => new SOAP_Value('error_code', 'string', $error_code), "items" => new SOAP_Value('items', $array, $items) ) );*/ return new SOAP_Value('return', $result, $array_input); }
public function upload() { // Creating response to send $response = new stdClass(); $current_time = date('Y-m-d H:i:s'); $this->load->library('upload'); $files_data = array('marks' => null, 'email' => null); // Validating files foreach ($files_data as $file_name => $data) { $response->{$file_name} = new stdClass(); if ($_FILES and isset($_FILES[$file_name]) and $_FILES[$file_name]['name']) { $e = str_replace('.', '-', $this->auth_lib->user()->email); $ip = str_replace('.', '-', $this->input->ip_address()); $tmp_file_name = 'tmp_' . $file_name . '_file_by_' . $e . '_from_' . $ip . '_at_' . $current_time; $this->upload->initialize(array('file_name' => $tmp_file_name, 'upload_path' => $this->config->item('upload_dir'), 'allowed_types' => 'csv')); $response->{$file_name}->success = $this->upload->do_upload($file_name); $response->{$file_name}->errors = $this->upload->display_errors('', ''); $response->{$file_name}->data = $this->upload->data(); $files_data[$file_name] = $this->upload->data(); } else { $response->{$file_name}->success = false; $response->{$file_name}->errors = "Please select {$file_name} file"; } } // Validating input data $form_validation_success = true; foreach ($files_data as $name => $data) { if (!$response->{$name}->success) { $form_validation_success = false; break; } } if (!$form_validation_success) { echo json_encode($response); exit; } // Reading files to check the fields are proper. $this->load->library('excel_reader'); // Marks file $marks = $this->excel_reader->read($files_data['marks']['full_path']); $marks_fields = array(); foreach ($marks->get_fields() as $m_field) { $marks_fields[strtolower($m_field)] = $m_field; } // Email file $emails = $this->excel_reader->read($files_data['email']['full_path']); $e_fields = $emails->get_fields(); $email_diff = array_diff(array('roll_no', 'father_email_id'), $e_fields); if (count($email_diff) > 0) { $response->email->success = false; $response->email->errors = 'Field ' . implode(', ', $email_diff) . ' not found in email file'; } if (!$response->email->success) { echo json_encode($response); exit; } $email_fields = array(); foreach ($e_fields as $e_field) { $email_fields[strtolower($e_field)] = $e_field; } // Everything seems fine now. Creating task to start sending emails $this->load->model('task'); $task = $this->task->create_task($this->auth_lib->user()->email, $this->input->ip_address(), $current_time); $task_id = $task->id; $this->load->library('session'); $this->session->set_userdata('task_id', $task_id); $response->task_id = $task_id; // send response with task_id and start background processing $this->load->library('bg_processing'); $this->bg_processing->send_and_close(json_encode($response)); $this->task->set_task_status($task_id, 'processing'); // Renaming uploaded files foreach ($files_data as $file_name => $data) { $new_name = $file_name . '_file_for_task_' . $task_id . $data['file_ext']; $new_full_path = $data['file_path'] . $new_name; rename($data['full_path'], $new_full_path); $data['file_name'] = $new_name; $files_data[$file_name]['full_path'] = $new_full_path; } $this->load->model('student'); $this->load->model('course'); $months = array('jan', 'feb', 'mar', 'apr', 'may', 'jun', 'jul', 'aug', 'sep', 'oct', 'nov', 'dec'); $months_available = array(); foreach ($months as $month) { if (in_array($month . '-classes', array_keys($marks_fields))) { $months_available[] = $month; } } $CI = $this; $CI->task->insert_status_msg($task_id, "Info: Started reading marks file"); $marks->each(function ($a) use($task_id, $months_available, $marks_fields, $CI) { if (!$a->roll_no) { return; } $student = $CI->student->get_or_create($a->roll_no, $a->name, null, $a->SGPA); $course_id = $CI->course->get_or_create($a->course_code, $a->course_name, $a->credits); $classes_total = 0; $classes_missed = 0; foreach ($months_available as $month) { $classes_total += $a->get($marks_fields[$month . '-classes']); $classes_missed += $a->get($marks_fields[$month . '-absents']); } $CI->course->insert_marks_info(array('task_id' => $task_id, 'student_id' => $student->id, 'course_id' => $course_id, 'max_marks' => $a->get('max-marks'), 'marks_secured' => $a->get('marks-obtained'), 'classes_total' => $classes_total, 'classes_missed' => $classes_missed, 'grade' => $a->get('Grade'))); }); $CI->task->insert_status_msg($task_id, "Info: End reading marks file"); $this->load->library('email_wrapper'); $CI->task->insert_status_msg($task_id, "Info: Started sending emails"); $emails->each(function ($a) use($task, $CI) { if (!$a->roll_no || !$a->father_email_id) { return; } $task_id = $task->id; $student = $CI->student->get_or_create($a->roll_no, null, $a->father_email_id); $course_data = $CI->course->get_data($task_id, $student->id); if (count($course_data)) { my_log($student->parent_email . ' - ' . count($course_data)); $email_success = $CI->email_wrapper->send($student, $course_data, $task); if ($email_success) { $CI->task->increase_sent_email($task_id); my_log("Task {$task_id}: Success: Email to {$student->parent_email} sent successfully"); $CI->task->insert_status_msg($task_id, "Success: Email to {$student->parent_email} sent successfully"); } else { $CI->task->increase_failed_email($task_id); $CI->task->insert_status_msg($task_id, "Warning: Email to {$student->parent_email} failed"); } } else { $CI->task->insert_status_msg($task_id, "Info: No marks or attendance found for student with roll_no {$student->roll_no}"); } }); $CI->task->insert_status_msg($task_id, "Info: Completed sending emails"); $this->task->complete($task_id, date('Y-m-d H:i:s')); }
function snts_n_days_later($n) { if ($n <= 0) { my_log(__FILE__, "n should be bigger than 0\n"); exit(1); } $is_n_days_later = function ($snt) use($n) { $n_days_later = strtotime("+{$n} day"); if ((int) date('Y', $n_days_later) === $snt["when"]["year"] && (int) date('m', $n_days_later) === $snt["when"]["month"] && (int) date('d', $n_days_later) === $snt["when"]["day"]) { return true; } else { return false; } }; return array_filter(get_schedule(), $is_n_days_later); }
function my_onReceive(swoole_server $serv, $fd, $from_id, $data) { my_log("Worker#{$serv->worker_pid} Client[{$fd}@{$from_id}]: received: {$data}"); $cmd = trim($data); if ($cmd == "reload") { $serv->reload(); } elseif ($cmd == "task") { $serv->task("task-" . $fd); } elseif ($cmd == "taskwait") { $result = $serv->taskwait("taskwait"); if ($result) { $serv->send($fd, "taskwaitok"); } } elseif ($cmd == "taskWaitMulti") { $tasks = array('taskWaitMulti', 'taskWaitMulti'); $result = $serv->taskWaitMulti($tasks); if (is_array($result)) { $serv->send($fd, "taskWaitMulti OK"); } else { $serv->send($fd, "taskWaitMulti error"); } } elseif ($cmd == "hellotask") { $serv->task("hellotask"); } elseif ($cmd == "sendto") { $serv->sendto("127.0.0.1", 9999, "hello world"); } elseif ($cmd == "close") { $serv->close($fd); } elseif ($cmd == "info") { $info = $serv->connection_info(strval($fd), $from_id); $serv->send($fd, serialize($info)); } elseif ($cmd == 'proxy') { $serv->send(1, "hello world\n"); } elseif ($cmd == 'sleep') { sleep(10); } elseif ($cmd == 'sendfile') { $serv->sendfile($fd, __DIR__ . '/test.jpg'); } elseif ($cmd == 'foreach') { foreach ($serv->connections as $fd) { echo "conn : {$fd}\n"; } return; } elseif ($cmd == 'tick') { $serv->tick(1000, function ($id) use($serv, $fd) { $serv->send($fd, "tick"); $serv->clearTimer($id); }); } elseif ($cmd == 'after') { $serv->after(1000, function ($id) use($serv, $fd) { $serv->send($fd, "after"); }); } elseif ($cmd == "list") { $start_fd = 0; echo "broadcast\n"; while (true) { $conn_list = $serv->connection_list($start_fd, 10); if (empty($conn_list)) { echo "iterates finished\n"; break; } $start_fd = end($conn_list); var_dump($conn_list); } } elseif ($cmd == "list2") { foreach ($serv->connections as $con) { var_dump($serv->connection_info($con)); } } elseif ($cmd == "stats") { $serv_stats = $serv->stats(); $serv->send($fd, 'Stats: ' . var_export($serv_stats, true) . "\ncount=" . count($serv->connections) . PHP_EOL); } elseif ($cmd == "broadcast") { broadcast($serv, $fd, "hello from {$fd}\n"); } elseif ($cmd == "error") { hello_no_exists(); } elseif ($cmd == "exit") { exit("worker php exit.\n"); } elseif (substr($cmd, 0, 5) == "close") { $close_fd = substr($cmd, 6); $serv->close($close_fd); } elseif ($cmd == "shutdown") { $serv->shutdown(); } elseif ($cmd == "fatalerror") { require __DIR__ . '/php/error.php'; } elseif ($cmd == 'sendbuffer') { $buffer = G::getBuffer($fd); $buffer->append("hello\n"); $serv->send($fd, $buffer); } elseif ($cmd == 'defer') { $serv->defer(function () use($fd, $serv) { $serv->close($fd); $serv->defer(function () { echo "deferd\n"; }); }); $serv->send($fd, 'Swoole: ' . $data, $from_id); } elseif ($cmd == 'big_resp') { $serv->send($fd, str_repeat('A', 256 * 1024)); } elseif ($cmd == 'big_task') { $serv->task($fd . ' ' . str_repeat('A', 256 * 1024 - 8)); } else { $serv->send($fd, 'Swoole: ' . $data, $from_id); //$serv->close($fd); } //echo "Client:Data. fd=$fd|from_id=$from_id|data=$data"; // $serv->after( // 800, function () { // echo "hello"; // } // ); //swoole_server_send($serv, $other_fd, "Server: $data", $other_from_id); }
function check_database($password) { $password = urldecode($password); $user_id = $this->input->post('user_id'); $result = $this->user->login($user_id, $password); if ($result) { my_log("LOGIN", "", $user_id); $sess_array = array(); foreach ($result as $row) { $sess_array = array('user_id' => $row->user_id, 'username' => $row->username, 'cid' => $row->cid); $this->session->set_userdata('logged_in', $sess_array); } return true; } else { $this->form_validation->set_message('check_database', lang('login_error')); return false; } }
function test($start = 0, $end = 0, $path = '') { if (empty($path)) { return; } $now = time(); logger("{$start}-{$end}", $now); $file_name = "/home/xuanwen/download/2016-03-18/{$start}-{$end}"; $temp_str = file_get_contents($file_name); $temp_str = trim($temp_str, ','); $temp_str = '[' . $temp_str . ']'; $temp_json = json_decode($temp_str, true); $count = 0; static $img_count = 0; static $mp3_count = 0; foreach ($temp_json as $value) { if ($value['audio']) { $audio = $value['audio']; $title_photo = is_empty($audio['title_photo']); $content_photo = is_empty($audio['content_photo']); $wetsound_path = is_empty($audio['wetsound_path']); $addPicList = is_empty($audio['addPicList']); if ($addPicList) { read_pics($addPicList, $path); } build_img($title_photo, $path, $img_count); build_img($content_photo, $path, $img_count); build_mp3($wetsound_path, $path, $mp3_count); $count++; } if ($count == 10) { break; } } my_log($count, $img_count, $mp3_count); $img_count = 0; $mp3_count = 0; $use_time = time() - $now; logger("{$start}-{$end} ENDED", $use_time); }
function my_onReceive(swoole_server $serv, $fd, $from_id, $data) { my_log("Worker#{$serv->worker_pid} Client[{$fd}@{$from_id}]: received: {$data}"); $cmd = trim($data); if ($cmd == "reload") { $serv->reload(); } elseif ($cmd == "task") { $task_id = $serv->task("task-" . $fd); echo "Dispath AsyncTask: id={$task_id}\n"; } elseif ($cmd == "taskwait") { $result = $serv->taskwait("taskwait"); if ($result) { $serv->send($fd, "taskwaitok"); } echo "SyncTask: result=" . var_export($result, true) . "\n"; } elseif ($cmd == "hellotask") { $serv->task("hellotask"); } elseif ($cmd == "sendto") { $serv->sendto("127.0.0.1", 9999, "hello world"); } elseif ($cmd == "close") { $serv->send($fd, "close connection\n"); $result = $serv->close($fd); } elseif ($cmd == "info") { $info = $serv->connection_info(strval($fd), $from_id); var_dump($info["remote_ip"]); $serv->send($fd, 'Info: ' . var_export($info, true) . PHP_EOL); } elseif ($cmd == 'proxy') { $serv->send(1, "hello world\n"); } elseif ($cmd == 'sleep') { sleep(10); } elseif ($cmd == 'foreach') { foreach ($serv->connections as $fd) { echo "conn : {$fd}\n"; } return; } elseif ($cmd == 'tick') { $serv->tick(2000, function ($id) { echo "tick #{$id}\n"; }); } elseif ($cmd == 'addtimer') { $serv->addtimer(3000); } elseif ($cmd == "list") { $start_fd = 0; echo "broadcast\n"; while (true) { $conn_list = $serv->connection_list($start_fd, 10); if (empty($conn_list)) { echo "iterates finished\n"; break; } $start_fd = end($conn_list); var_dump($conn_list); } } elseif ($cmd == "list2") { foreach ($serv->connections as $con) { var_dump($serv->connection_info($con)); } } elseif ($cmd == "stats") { $serv_stats = $serv->stats(); $serv->send($fd, 'Stats: ' . var_export($serv_stats, true) . PHP_EOL); } elseif ($cmd == "broadcast") { broadcast($serv, $fd, "hello from {$fd}\n"); } elseif ($cmd == "error") { hello_no_exists(); } elseif ($cmd == "exit") { exit("worker php exit.\n"); } elseif (substr($cmd, 0, 5) == "close") { $close_fd = substr($cmd, 6); $serv->close($close_fd); } elseif ($cmd == "shutdown") { $serv->shutdown(); } elseif ($cmd == 'sendbuffer') { $buffer = G::getBuffer($fd); $buffer->append("hello\n"); $serv->send($fd, $buffer); } else { $ret = $serv->send($fd, 'Swoole: ' . $data, $from_id); var_dump($ret); //$serv->close($fd); } //echo "Client:Data. fd=$fd|from_id=$from_id|data=$data"; // $serv->after( // 800, function () { // echo "hello"; // } // ); //swoole_server_send($serv, $other_fd, "Server: $data", $other_from_id); }
} } function confirm_notice($snt) { $msg = gen_total_msg($snt); echo_msg($msg); $confirm = ask_y_or_n("Are you sure to send the above message?"); if ($confirm) { echo "Comment mail will be sent.\n\n"; send($msg); } else { echo "Comment mail is cancelled.\n\n"; } } function manual() { echo "Welcome to S&T comment system.\n\n"; $snt = select_snt(); confirm_notice($snt); echo "Bye.\n"; } if ($argc === 1) { manual(); } else { if ($argv[1] === "auto") { auto(); } else { my_log(__FILE__, "Command arguments are invalid\n"); exit(1); } }
<?php function add3($x1, $x2, $x3) { return $x1 + $x2 + $x3; } add3(1, 2, 3); # function names are case insensitive: ADD3(1, 2, 3); function my_log($x, $base = 10) { return log($x) / log($base); } my_log(42); my_log(42, M_E); function first_and_last() { $arg_cnt = func_num_args(); if ($arg_cnt >= 1) { $n = func_get_arg(0); echo "first: " . $n . "\n"; } if ($arg_cnt >= 2) { $a = func_get_args(); $n = $a[$arg_cnt - 1]; echo "last: " . $n . "\n"; } } $a = [1, 2, 3]; call_user_func_array("add3", $a); function first_and_second(&$a)
{ return date('Y-m-d H:i', time_of_when($when)); } echo "<ul>\n"; foreach (get_exception_conf() as $exc) { echo "<li>\n"; if ($exc["mode"] == "remove") { echo "취소: " . str_of_when($exc["when"]); } else { if ($exc["mode"] == "add") { echo "추가: " . str_of_when($exc["when"]) . " @ " . $exc["where"]; } else { if ($exc["mode"] == "modify") { echo "변경: " . str_of_when($exc["from"]) . htmlspecialchars(" => ") . str_of_when($exc["when"]) . " @ " . $exc["where"]; } else { my_log(__FILE__, "Invalid mode name in exception\n"); exit(1); } } } echo "</li>\n"; } echo "</ul>\n"; ?> </div> <div class="section"> <h2>쇼앤텔 일정</h2> <?php
function my_onClose($serv, $fd, $from_id) { my_log("Client[{$fd}@{$from_id}]: fd={$fd} is closed"); }
/** Description: ; input: classname,$functionname,$errorcode, items return array */ function returnXML($arrArgs, $class_name, $function_name, $error_code, $items, $obj = NULL) { $count = count($arrArgs); $user = $arrArgs[$count - 2]; $input = "[INPUT: "; for ($i = 0; $i < $count; $i++) { $input .= $arrArgs[$i] . "\t"; } $kind = " [" . $class_name . ":" . $function_name . "]" . $input . "] "; $detail = $kind . $obj->_MDB2_WRITE->last_query . " --> " . $error_code; my_log($user, 'ALL', $detail); $result = "{urn:" . $class_name . "}" . $function_name . "Result"; $array = "{urn:" . $class_name . "}" . $function_name . "Array"; return new SOAP_Value('return', $result, array("error_code" => new SOAP_Value('error_code', 'string', $error_code), "items" => new SOAP_Value('items', $array, $items))); }
my_log("\n\nAguardando Espera (20 segundos) ..."); sleep(20); my_log("Iniciando Teste de Internet ..."); while ($cont < 2) { while (list($site, $ip) = each($servidores)) { $comando = "/bin/ping -c 1 " . $ip; $saida = shell_exec($comando); if (ereg("bytes from", $saida)) { $sem_conexao = 0; my_log("\nConexao Normal com a Internet ...."); my_log("Teste: {$site} IP: {$ip} "); my_log("Numero do Teste: {$test} "); } else { $sem_conexao++; my_log("\nOPS, Sem Conexao com a Internet ... "); my_log("Teste: {$site} IP: {$ip} "); my_log("Numero do Teste: {$test} "); } $cont++; $test++; } if ($sem_conexao == 2) { my_log("\nOPS, a verificacao concluiu que estamos sem Internet ! em {$data}"); my_log("Fazendo reboot agora .... em {$data}"); shell_exec($reboot); my_log("Aguardando 45 segundos ate que o gateway seja atualizado ..."); sleep(45); my_log("Gateway atualizado .... em {$data}"); } } }
public function m1() { global $_QueryAction, $_QueryMethod; my_log($_QueryAction); my_log($_QueryMethod); }
break; case '2': $re = $dab->editBlockMoney($result['bankaccount'], $result['accountno'], $_REQUEST['OrderID'], $_REQUEST['Amount']); $detail = $result['bankaccount'] . ", " . $result['accountno'] . ", " . $_REQUEST['OrderID'] . ", " . $_REQUEST['Amount']; break; case '3': $re = $dab->cancelBlockMoney($result['bankaccount'], $result['accountno'], $_REQUEST['OrderID'], $_REQUEST['Amount']); $detail = $result['bankaccount'] . ", " . $result['accountno'] . ", " . $_REQUEST['OrderID'] . ", " . $_REQUEST['Amount']; break; case '4': $re = $dab->cutMoney($result['bankaccount'], $result['accountno'], $_REQUEST['OrderID'], $_REQUEST['Amount'], $_REQUEST['Fee']); $detail = $result['bankaccount'] . ", " . $result['accountno'] . ", " . $_REQUEST['OrderID'] . ", " . $_REQUEST['Amount'] . ", " . $_REQUEST['Fee']; break; } //switch my_log('ba.nd', 'ALL', $detail); session_register('Error'); $_SESSION['Error'] = $re; header("Location: exchange.php"); exit; } else { // if ORderID session_register('Error'); $_SESSION['Error'] = "OrderID is not exist"; header("Location: exchange.php"); exit; } } } else { header("Location: index.php"); exit;
/** * Gets first entry for given Station ID, destinantion Array (to filter for * trains going in a certian direction but terminating at an earlier station) * * @param string $station_id The Station ID (like "1310") * @param array $dest Array with all wanted destinantions like array("Mittersendling", "Pasing") * @param int $line The wanted line number * @return array A single departure array like shown in get_deps_for_station_id() */ function get_first_dept_for_station_id($station_id, $dest, $line) { global $min_time_to_departure; $deps = get_deps_for_station_id($station_id); if (empty($deps)) { my_log("Empty array!", 1); } for ($i = 0; $i < count($deps); $i++) { // echo $i; $d = $deps[$i]; if (in_array($d['destination'], $dest) && $d['departureTime'] / 1000 - time() > $min_time_to_departure && $d['label'] == $line) { return $deps[$i]; } } }
function my_onTimer($serv, $interval) { my_log("Server:Timer Call.Interval={$interval}"); }
function tmp_test2() { my_log("==="); file_get_contents("http://112.124.26.68/zsgjs2/trunk/Admin/A/Test/pxltest"); }