Command Line Tools Every PHP Developer Should Know About
Upcoming SlideShare
Loading in...5
×
 

Command Line Tools Every PHP Developer Should Know About

on

  • 2,391 views

With the increasing selection of modern IDEs supporting the PHP syntax and their bells and whistles, developers often lose sight of the command line and all of the utility it offers. Working with GNU ...

With the increasing selection of modern IDEs supporting the PHP syntax and their bells and whistles, developers often lose sight of the command line and all of the utility it offers. Working with GNU tools can be a great way to identify problems, come up with creative and time saving solutions, and bolster your development productivity. I'll cover a variety of must-know commands you might not know about so that you can be prepared for your next big problem.

Statistics

Views

Total Views
2,391
Views on SlideShare
2,386
Embed Views
5

Actions

Likes
0
Downloads
6
Comments
0

3 Embeds 5

http://www.linkedin.com 3
http://paper.li 1
https://www.linkedin.com 1

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

CC Attribution-NonCommercial-ShareAlike LicenseCC Attribution-NonCommercial-ShareAlike LicenseCC Attribution-NonCommercial-ShareAlike License

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

Command Line Tools Every PHP Developer Should Know About Command Line Tools Every PHP Developer Should Know About Presentation Transcript

  • Command Line Tools Every PHP Developer Should Know About
    By Andrew Kandels
  • File Operations
    tail -f Output appended data as the file grows
    Filter output with egrep: tail –f /log/file | egrep “ip-address”
    lsof List open files (think of “ls open files”)
  • strace
    Traces the name of every system call, its arguments and return value.
    Trick for strace’ing web requests:
    strace –o /tmp/webtraffic.log –f /etc/init.d/apache2 start &
    tail –f /tmp/webtraffic.log | egrep “No such file”
  • Bash Command History
    /etc/profile Improvements
    export HISTCONTROL=erasedups
    export HISTSIZE=10000
    shopt -shistappend
    !! Run last command
    !string Run last command that matches string
    !$ Last argument from last command (bang-bling)
    CTRL-R Search/auto-complete command history
    $? Exit code from last command (0 = win)
  • Get Some Stats
    Step #1: Is there a problem? Get the CPU load.
    1m 5m 15m
    mpstat CPU stats
    iostat File I/O stats
    top/htop Process/various other stats
    cat /proc/loadavg Load averages
    netstat Network stats
    free -m Free memory/swap stats
    netstat –tlpGet the listening TCP sockets (what ports are open)
  • screen
    Recoverable screen manager that emulates a VT100/ANSI terminal.
    CTRL-a <command>
    cCreate new window
    “ List windows
    If you lose your connection, use screen –list to list previous screen sessions, and
    screen –r # to recover a session:
  • processes
    ps –aux List all processes
    pstree –p List processes in a tree (parent/child)
    htop Interactively list all processes (with tree option)
    apachetop View Apache connections interactively
    mytop View MySQL queries interactively
    iotop View I/O operations interactively
  • There’s a Command For That
    strings <file> List readable strings in a binary (or any) file
    file <file> What kind of file is it?
    stat <file> atime, ctime, mtime, size, type, inode
    dig <url> Resolve a domain name into an IP address (and measure)
    arp –a View the local ARP cache
    cat /proc/cpuinfo How many CPUs do I have?
    free –m How much memory am I using?
    df –h How much disk space am I using?
    du –ch /path How much space is a folder using?
    echo $((2*4)) Quick math
  • awk
    Pattern scanning and text processing language (it’s like pixie dust in vim)
    NR = Number or Records read so far
    NF = Number of Fields in current record
    FS = the Field Separator
    RS = the Record Separator
    BEGIN = a pattern that's only true before processing any input
    END = a pattern that's only true after processing all input.
    sed
    Stream editor to replace text in file(s), delete lines and so much more.
    In-place replace 2010 copyrights with 2011 in all PHP files:
    find . –type f –name “*.php” –exec sed -I’’ ‘s/Copyright 2010/Copyright 2011/g’ ;
  • httperf
    http://www.hpl.hp.com/research/linux/httperf/
    Stress test your server by simulating web traffic.
    Beat the crap out of your server:
    for x in {1..10}; do
    httperf --hog –server=domain.com –wsess=250,5,10 --burst-length=5 --rate 100 --timeout 5 --uri /path/to/file
    echo “Run #$x… “
    sleep 1
    done
    250 – Number of clients
    100 – Requests per second
    Test load (server side):
    while [ true ]; do uptime; sleep 5; done