无需言 做自己 业 ,精于勤 荒于嬉.

OPcache 函数 opcache_get_status 获取缓存的状态信息

发表日期:2021-07-01 08:55:01 | 来源: | 分类:OPcache 函数

opcache_get_status

(PHP 5 >= 5.5.0, PHP 7, PHP 8, PECL ZendOpcache > 7.0.2)

opcache_get_status获取缓存的状态信息

说明

opcache_get_status(boolean $get_scripts = true): array

该函数将返回缓存实例的状态信息。

参数

get_scripts

包含脚本的具体声明信息。

返回值

返回一个数组,该数组可能包含有脚本具体的声明信息。

错误/异常

在启用了 opcache.restrict_api 的情况下,如果当前路径在禁止规则里,将会出现 E_WARNING ;不会返回任何状态信息。

参见

阅读全文 »

OPcache 函数 opcache_get_configuration 获取缓存的配置信息

发表日期:2021-07-01 08:55:00 | 来源: | 分类:OPcache 函数

opcache_get_configuration

(PHP 5 >= 5.5.0, PHP 7, PHP 8, PECL ZendOpcache > 7.0.2)

opcache_get_configuration获取缓存的配置信息

说明

opcache_get_configuration(): array

该函数将返回缓存实例的配置信息。

返回值

返回一个数组,该数组里包含了缓存的初始化信息,黑名单和版本号。

错误/异常

在启用了 opcache.restrict_api 的情况下,如果当前路径在禁止规则里,将会出现 E_WARNING ;不会返回任何状态信息。

参见

阅读全文 »

OPcache 函数 opcache_compile_file 无需运行,即可编译并缓存 PHP 脚本

发表日期:2021-07-01 08:55:00 | 来源: | 分类:OPcache 函数

opcache_compile_file

(PHP 5 >= 5.5.5, PHP 7, PHP 8, PECL ZendOpcache > 7.0.2)

opcache_compile_file无需运行,即可编译并缓存 PHP 脚本

说明

opcache_compile_file(string $file): boolean

该函数可以用于在不用运行某个 PHP 脚本的情况下,编译该 PHP 脚本并将其添加到字节码缓存中去。 该函数可用于在 Web 服务器重启之后初始化缓存,以供后续请求调用。

参数

file

被编译的 PHP 脚本的路径。

返回值

如果 file 被成功编译,则返回 true 或者在失败时返回 false

错误/异常

如果文件( file )不能被载入或者不能被编译,则会生成一个 E_WARNING 级别的错误。 可以使用 @ 来抑制该警告。

参见

阅读全文 »

OPcache 函数 opcache_reset 重置字节码缓存的内容

发表日期:2021-07-01 08:55:00 | 来源: | 分类:OPcache 函数

opcache_reset

(PHP 5 >= 5.5.0, PHP 7, PHP 8, PECL ZendOpcache >= 7.0.0)

opcache_reset重置字节码缓存的内容

说明

opcache_reset(): boolean

该函数将重置整个字节码缓存。 在调用 opcache_reset() 之后,所有的脚本将会重新载入并且在下次被点击的时候重新解析。

参数

此函数没有参数。

返回值

如果字节码缓存被重置成功,则返回 true;如果字节码缓存被禁用,则返回 false

参见

阅读全文 »

OPcache 函数 opcache_invalidate 废除脚本缓存

发表日期:2021-07-01 08:55:00 | 来源: | 分类:OPcache 函数

opcache_invalidate

(PHP 5 >= 5.5.0, PHP 7, PHP 8, PECL ZendOpcache >= 7.0.0)

opcache_invalidate废除脚本缓存

说明

opcache_invalidate(string $script, boolean $force = false): boolean

该函数的作用是使得指定脚本的字节码缓存失效。 如果 force 没有设置或者传入的是 false,那么只有当脚本的修改时间 比对应字节码的时间更新,脚本的缓存才会失效。

参数

script

缓存需要被作废对应的脚本路径

force

如果该参数设置为true,那么不管是否必要,该脚本的缓存都将被废除。

返回值

如果脚本的字节码缓存失效设置成功或者该脚本本来就没有缓存,则返回 true;如果字节码缓存被禁用,则返回false

参见

阅读全文 »

OPcache 函数 opcache_is_script_cached Tells whether a script is cached in OPCache

发表日期:2021-07-01 08:55:00 | 来源: | 分类:OPcache 函数

opcache_is_script_cached

(PHP 5 >= 5.5.11, PHP 7, PHP 8, PECL ZendOpcache >= 7.0.4)

opcache_is_script_cachedTells whether a script is cached in OPCache

说明

opcache_is_script_cached(string $filename): bool

This function checks if a PHP script has been cached in OPCache. This can be used to more easily detect the "warming" of the cache for a particular script.

参数

filename

The path to the PHP script to be checked.

返回值

Returns true if filename is cached in OPCache, false otherwise.

参见

阅读全文 »

错误处理 函数 error_log 发送错误信息到某个地方

发表日期:2021-07-01 08:54:56 | 来源: | 分类:错误处理 函数

      示例1
<?php 
// 如果无法连接到数据库,发送通知到服务器日志if (!Ora_Logon($username, $password)) {
    error_log("Oracle database not available!", 0);
}
// 如果用尽了 FOO,通过邮件通知管理员if (!($foo = allocate_new_foo())) {
    error_log("Big trouble, we're all out of FOOs!", 1,               "operator@example.com");
}
// 调用 error_log() 的另一种方式:error_log("You messed up!", 3, "/var/tmp/my-errors.log");
?>

阅读全文 »

错误处理 函数 restore_error_handler 还原之前的错误处理函数

发表日期:2021-07-01 08:54:56 | 来源: | 分类:错误处理 函数

      示例1
<?php 
function unserialize_handler($errno, $errstr){
    echo "Invalid serialized value.\n";
}
$serialized = 'foo';
set_error_handler('unserialize_handler');
$original = unserialize($serialized);
restore_error_handler();
?>

阅读全文 »

错误处理 函数 error_reporting 设置应该报告何种 PHP 错误

发表日期:2021-07-01 08:54:56 | 来源: | 分类:错误处理 函数

      示例1
<?php 
// 关闭所有PHP错误报告error_reporting(0);
// Report simple running errorserror_reporting(E_ERROR | E_WARNING | E_PARSE);
// 报告 E_NOTICE也挺好 (报告未初始化的变量// 或者捕获变量名的错误拼写)error_reporting(E_ERROR | E_WARNING | E_PARSE | E_NOTICE);
// 除了 E_NOTICE,报告其他所有错误error_reporting(E_ALL ^ E_NOTICE);
// 报告所有 PHP 错误 (参见 changelog)error_reporting(E_ALL);
// 报告所有 PHP 错误error_reporting(-1);
// 和 error_reporting(E_ALL);
 一样ini_set('error_reporting', E_ALL);
?>

阅读全文 »

错误处理 函数 debug_backtrace 产生一条回溯跟踪(backtrace)

发表日期:2021-07-01 08:54:56 | 来源: | 分类:错误处理 函数

      示例1
<?php 
// filename: /tmp/a.phpfunction a_test($str){
    echo "\nHi: $str";
    var_dump(debug_backtrace());
}
a_test('friend');
?><?php// filename: /tmp/b.phpinclude_once '/tmp/a.php';
?>

阅读全文 »

错误处理 函数 restore_exception_handler 恢复之前定义过的异常处理函数。

发表日期:2021-07-01 08:54:56 | 来源: | 分类:错误处理 函数

      示例1
<?php 
    function exception_handler_1(Exception $e)    {
        echo '[' . __FUNCTION__ . '] ' . $e->getMessage();
    }
    function exception_handler_2(Exception $e)    {
        echo '[' . __FUNCTION__ . '] ' . $e->getMessage();
    }
    set_exception_handler('exception_handler_1');
    set_exception_handler('exception_handler_2');
    restore_exception_handler();
    throw new Exception('This triggers the first exception handler...');
?>

阅读全文 »

错误处理 函数 trigger_error 产生一个用户级别的 error/warning/notice 信息

发表日期:2021-07-01 08:54:56 | 来源: | 分类:错误处理 函数

      示例1
<?php 
if ($divisor == 0) {
    trigger_error("Cannot divide by zero", E_USER_ERROR);
}
?>

阅读全文 »

错误处理 函数 user_error trigger_error() 的别名

发表日期:2021-07-01 08:54:56 | 来源: | 分类:错误处理 函数

user_error

(PHP 4, PHP 5, PHP 7, PHP 8)

user_errortrigger_error() 的别名

说明

此函数是该函数的别名: trigger_error().

阅读全文 »

错误处理 函数 set_exception_handler 设置用户自定义的异常处理函数

发表日期:2021-07-01 08:54:56 | 来源: | 分类:错误处理 函数

      示例1
<?php 
function exception_handler($exception) {
  echo "Uncaught exception: " , $exception->getMessage(), "\n";
}
set_exception_handler('exception_handler');
throw new Exception('Uncaught Exception');
echo "Not Executed\n";
?>

阅读全文 »

错误处理 函数 set_error_handler 设置用户自定义的错误处理函数

发表日期:2021-07-01 08:54:56 | 来源: | 分类:错误处理 函数

      示例1
<?php 
// error handler functionfunction myErrorHandler($errno, $errstr, $errfile, $errline){
    if (!(error_reporting() & $errno)) {
        // This error code is not included in error_reporting, so let it fall        // through to the standard PHP error handler        return false;
    }
    // $errstr may need to be escaped:    $errstr = htmlspecialchars($errstr);
    switch ($errno) {
    case E_USER_ERROR:        echo "<b>My ERROR</b> [$errno] $errstr<br />\n";
        echo "  Fatal error on line $errline in file $errfile";
        echo ", PHP " . PHP_VERSION . " (" . PHP_OS . ")<br />\n";
        echo "Aborting...<br />\n";
        exit(1);
    case E_USER_WARNING:        echo "<b>My WARNING</b> [$errno] $errstr<br />\n";
        break;
    case E_USER_NOTICE:        echo "<b>My NOTICE</b> [$errno] $errstr<br />\n";
        break;
    default:        echo "Unknown error type: [$errno] $errstr<br />\n";
        break;
    }
    /* Don't execute PHP internal error handler */
    return true;
}
// function to test the error handlingfunction scale_by_log($vect, $scale){
    if (!is_numeric($scale) || $scale <= 0) {
        trigger_error("log(x) for x <= 0 is undefined, you used: scale = $scale", E_USER_ERROR);
    }
    if (!is_array($vect)) {
        trigger_error("Incorrect input vector, array of values expected", E_USER_WARNING);
        return null;
    }
    $temp = array();
    foreach($vect as $pos => $value) {
        if (!is_numeric($value)) {
            trigger_error("Value at position $pos is not a number, using 0 (zero)", E_USER_NOTICE);
            $value = 0;
        }
        $temp[$pos] = log($scale) * $value;
    }
    return $temp;
}
// set to the user defined error handler$old_error_handler = set_error_handler("myErrorHandler");
// trigger some errors, first define a mixed array with a non-numeric itemecho "vector a\n";
$a = array(2, 3, "foo", 5.5, 43.3, 21.11);
print_r($a);
// now generate second arrayecho "----\nvector b - a notice (b = log(PI) * a)\n";
/* Value at position $pos is not a number, using 0 (zero) */
$b = scale_by_log($a, M_PI);
print_r($b);
// this is trouble, we pass a string instead of an arrayecho "----\nvector c - a warning\n";
/* Incorrect input vector, array of values expected */
$c = scale_by_log("not array", 2.3);
var_dump($c);
 // NULL// this is a critical error, log of zero or negative number is undefinedecho "----\nvector d - fatal error\n";
/* log(x) for x <= 0 is undefined, you used: scale = $scale" */
$d = scale_by_log($a, -2.5);
var_dump($d);
 // Never reached?>

阅读全文 »

错误处理 函数 debug_print_backtrace 打印一条回溯。

发表日期:2021-07-01 08:54:55 | 来源: | 分类:错误处理 函数

      示例1
<?php 
// include.php filefunction a() {
    b();
}
function b() {
    c();
}
function c(){
    debug_print_backtrace();
}
a();
?>

      示例2
<?php 
// 文件 test.php// 这是你应该运行的文件include 'include.php';
?>

阅读全文 »

错误处理 函数 error_clear_last 清除最近一次错误

发表日期:2021-07-01 08:54:55 | 来源: | 分类:错误处理 函数

      示例1
<?php 
var_dump(error_get_last());
error_clear_last();
var_dump(error_get_last());
@$a = $b;
var_dump(error_get_last());
error_clear_last();
var_dump(error_get_last());
?>

阅读全文 »

错误处理 函数 error_get_last 获取最后发生的错误

发表日期:2021-07-01 08:54:55 | 来源: | 分类:错误处理 函数

      示例1
<?php 
echo $a;
print_r(error_get_last());
?>

阅读全文 »

JAVA基础 8.File 文件

发表日期:2021-06-30 20:01:30 | 来源: | 分类:JAVA基础

      示例1
import java.io.File;
import java.io.IOException;


public class FileDemo01 {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		
		File file = new File("d:"+File.separator+"test.txt");

		System.out.println(File.separator);// \
		System.out.println(File.separatorChar);// \
		System.out.println(File.pathSeparator);// ;
		System.out.println(File.pathSeparatorChar);// ;
		try {
			file.createNewFile();//创建文件
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		if(file.exists()){//判断文件是否存在
			//file.delete();//产出文件
		}
	}

}
      示例2
import java.io.File;



public class FileDemo02 {
	private static int ListModel = 0;//0:列文件夹和文件、1:只列出文件夹、2:只列出文件

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		ListModel = 1;
		File file = new File("d:"+File.separator);
		listFile(file);
		
	}
	
	private static void listFile(File file) {
		// TODO Auto-generated method stub
		
		if (file!=null) {
			if (file.isDirectory()) {
				if (ListModel!=2) {
					System.out.println(file);//列出文件夹
				}
				File str[]  = file.listFiles();
				if (str!=null) {
					for (int i = 0; i < str.length; i++) {
						listFile(str[i]);
					}
				}
			}else {
				if (ListModel!=1) {
					System.out.println(file);//列出文件夹
				}
			}
		}
	}

}
      示例3
package File;

import java.io.File;
import java.io.IOException;

public class FileDemo {

   /**
    * @param args
    */
   public static void main(String[] args) {
      // TODO Auto-generated method stub

      File file = new File("D:"+File.separator+"test.txt");
      if(!file.exists()){
         try {
            System.out.println("文件不存在,创建!");
            file.createNewFile();
         } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
         }
      }else {
         System.out.println("文件存在,不创建!");
      }

      File dir = new File("D:"+File.separator+"dir");

      if(!dir.exists()){
         System.out.println("文件夹不存在,创建!");
         dir.mkdir();
      }
      if(file.exists()){
         file.delete();
         System.out.println("删除文件!");
      }
      File disk = new File("D:"+File.separator);
      String[] lists = disk.list();//只列出名称
      for (int i = 0; i < lists.length; i++) {
         System.out.println(lists[i]);
      }

      File[] lists2 = disk.listFiles();//列出完整路径
      for (int i = 0; i < lists2.length; i++) {

         if (isDir(lists2[i].toString())) {
            System.out.println(lists2[i]+"是目录");
         }else {
            System.out.println(lists2[i]+"不是目录");
         }
      }


   }

   public static boolean isDir(String path){
      return new File(path).isDirectory();
   }

}

阅读全文 »

JAVA基础 16.Thead 多线程

发表日期:2021-06-30 19:58:59 | 来源: | 分类:JAVA基础

      示例1
class MyThead extends Thread {
	
	private  int ticket =10;

	private String name;
	
	
	public MyThead(String name){
		this.name = name;
	}
	
	public void run(){
		for (int i = 0; i < 10; i++) {
			if (this.ticket>0) {
				System.out.println(name+":"+i+"  ticket:"+ticket--);
			}
			
		}
	}

}
public class TheadDemo01 extends Thread {
	
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		MyThead m1 = new MyThead("A");
		MyThead m2 = new MyThead("B");
		/*
		m1.run(); 
		m2.run();
		A:0
		A:1
		A:2
		A:3
		A:4
		A:5
		A:6
		A:7
		A:8
		A:9
		B:0
		B:1
		B:2
		B:3
		B:4
		B:5
		B:6
		B:7
		B:8
		B:9
		run() 不会实现多线程
                */
		m1.start();
		m2.start();
	}

}
      示例2
class MyThead2 implements Runnable{

	private String name;
	private  int ticket =10;
	
	
	public MyThead2(String name){
		this.name = name;
	}
	
	public void run(){
		for (int i = 0; i < 10; i++) {
			if (ticket>0) {
				System.out.println(name+":"+i+"  ticket:"+ticket--);
			}
			
		}
	}

	public void start() {
		// TODO Auto-generated method stub
		
	}

}
public class TheadDemo02 {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub

		MyThead2 m1 = new MyThead2("A");
		MyThead2 m2 = new MyThead2("B");
		Thread t1 = new Thread(m1);
		Thread t2 = new Thread(m2);
		t1.start();
		t2.start();
		
		System.out.println(t2.getName());//setName() ...设置线程名称
	}

}
      示例3
class MyThead3 implements Runnable{

	private  int ticket =10;
	
	
	public MyThead3(){
	}
	
	public void run(){
		for (int i = 0; i < 10; i++) {
			if (this.ticket>0) {
				System.out.println(i+"   "+Thread.currentThread().getName()+"  ticket:"+ticket--);
			}
			
		}
	}

}
public class TheadDemo03 {

	/**
	 * @param args
	 */
	public static void main(String[] args) { 
		// TODO Auto-generated method stub

		MyThead3 mt = new MyThead3();
		new Thread(mt,"A").start();
		new Thread(mt,"B").start();
		new Thread(mt,"C").start();
	}

}
      示例4
class MyThread4 implements Runnable{
	private int ticket = 10;
	
	public MyThread4(){
	}
	
	public void run(){
		for (int i = 0; i < 10; i++) {
			
			//System.out.println(name+":"+i);
			
			if (this.ticket>0) {
				System.out.println(Thread.currentThread().getName()+":"+i+"  ticket:"+ticket--);
			}
			
		}
	}

	
}
public class TheadDemo04 {

	public static void main(String[] args) {
		// TODO 自动生成的方法存根

		MyThread4 mt1 = new MyThread4();
		new Thread(mt1).run();
		new Thread(mt1).run();
	}

}

阅读全文 »

全部博文(1589)
集速网 copyRight © 2015-2025 宁ICP备15000399号-1 宁公网安备 64010402001209号
与其临渊羡鱼,不如退而结网
欢迎转载、分享、引用、推荐、收藏。