PHP tips for a few humble children

Source: Internet
Author: User

It is not trivial to say that small tricks, in fact, should be said to be not commonly used in the regular application bar. A lot of things are like this, know is a horse thing, will use is a horse thing, fine learning is another horse thing. To become a master is a solid basic skill.

Str_repeat

Repeating the output string depends on it, similar to the X in Perl

Php-r ' echo str_repeat ("ABC", 5), "\ n"; '

Abcabcabcabcabc

Substr

This is used to intercept the word indicator, for example, to intercept the first letter of a string:

$string = ' ABCDEFG '

substr ($string, 0, 1) got a. But now I'm accustomed to using $string[0]. By the way, when judging if the length of the string is 7, now instead of the Isset ($string [6]), Because Isset is said to be faster than strlen. Similarly, this experience applies to count.

Trim

Trim this guy is used to go to the end of the gap and the end of the line. It took a long time, so that the author for it is specialized in doing this. I didn't think it would accept a parameter list to remove the unwanted characters, for example, to remove the '%abcdef% '%

Trim ('%abcdef% ', '% ')

Continue

This guy is used to skip the back loop. It takes a long time, the author always thought it is no parameter, until one time I want to jump out of a three-layer loop ...

Ini_set

When we write a network-based program, we consider that fault tolerance is necessary to set the socket time-out. The default time defined in PHP.ini is 60 seconds.

; Default timeout for socket based streams (seconds)

; Http://php.net/default-socket-timeout

Default_socket_timeout = 60

PHP manual can be used to modify the configuration of the php.ini Ini_set, so thought:

Ini_set (' Default_socket_timeout ', 6);

When I use some newly discovered functions, the habit is:

Var_dump (Ini_set (' Default_socket_timeout ', 6));

A running result tip:

String (2) "60"

Is it a setup failure? A couple of machines. Try it or that. Hey, what do you do? The study of a half-day finally found a problem, the PHP handbook is written:

Return Values

Returns the old value on success, FALSE on failure.

Hey, look at the manual is too careless!

Posix_kill

Nginx Log round-robin script I was written in PHP, in order to more PHP, notify Nginx to regenerate the new log when I used the Posix_kill:

Posix_kill ($nginx _PID,SIGUSR1)

On the N machines I use, this function is working properly. But lent the script to a man whose machine had reported:

Warning:posix_kill () expects parameter 2 to be long, string given

Look at the original function: bool Posix_kill (int $pid, int $sig)

The second argument does give an int. Why is SIGUSR1 on my machine, and the machine is going to die? php version problem? Dude's PHP version is higher than mine!

Online search for half a day SIGUSR1 corresponding int value is how much, unexpectedly can not find, finally still research kill command, inadvertently input: Kill-l got.

1) SIGHUP 2) SIGINT 3) Sigquit 4) Sigill

5) SIGTRAP 6) SIGABRT 7) Sigemt 8) SIGFPE

9) SIGKILL) Sigbus SIGSEGV) Sigsys

Sigpipe) sigalrm SIGTERM) Sigurg

SIGSTOP) SIGTSTP Sigcont) SIGCHLD

) (Sigttin) Sigttou () SIGIO) sigxcpu

SIGXFSZ) sigvtalrm sigprof) sigwinch

Siginfo SIGUSR1) SIGUSR2

The above is the Mac, and the Linux SIGUSR1 corresponding value is not the same, no words one.

1) SIGHUP 2) SIGINT 3) Sigquit 4) Sigill 5) SIGTRAP

6) SIGABRT 7) Sigbus 8) SIGFPE 9) SIGKILL) SIGUSR1

One) (SIGSEGV) (SIGUSR2) sigpipe) sigalrm) SIGTERM

Sigstkflt) (SIGCHLD) Sigcont SIGSTOP) SIGTSTP

(Sigttin) Sigttou () Sigurg) sigxcpu) Sigxfsz

(SIGVTALRM) sigprof) sigwinch SIGIO) SIGPWR

Sigsys) (sigrtmin) sigrtmin+1) sigrtmin+2 Notoginseng) sigrtmin+3

sigrtmin+4) sigrtmin+5 (sigrtmin+6) sigrtmin+7) sigrtmin+8

sigrtmin+9) (sigrtmin+10) sigrtmin+11 () sigrtmin+12) sigrtmin+13

(sigrtmin+14) sigrtmin+15 () SIGRTMAX-14) SIGRTMAX-13) SIGRTMAX-12

SIGRTMAX-11) SIGRTMAX-10 SIGRTMAX-9) SIGRTMAX-8 () SIGRTMAX-7

(SIGRTMAX-6) (SIGRTMAX-5) SIGRTMAX-4) SIGRTMAX-3) SIGRTMAX-2

SIGRTMAX-1) Sigrtmax

What if you want to support different systems at the same time? Add a judgment, PHP has a php_os called the artifact.

PHP tips for a few humble children

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.