21
php://memory redux

Php memory-redux

Embed Size (px)

DESCRIPTION

This is a follow-up to my PHP://memory and streams for scaling talk I gave at PHP|Tek12 in Chicago. Presented to the local Baltimore PHP User Group on 2012-06-20

Citation preview

Page 1: Php memory-redux

php://memoryredux

Page 2: Php memory-redux

say what

2001:558:1004:9:69:252:76:96

Page 3: Php memory-redux

say what

2001:558:1004:9:69:252:76:96

+ DNS..

Page 4: Php memory-redux

say what

2001:558:1004:9:69:252:76:96

+ Domain Name System

= ipv6.comcast.com

Page 5: Php memory-redux

who am i

Neal AndersSenior Software Engineer at Infobloxhttp://github.com/nanderoohttp://neal-anders.com@nanderoo

Page 6: Php memory-redux

before it was cool

Infoblox is working on some cool stuff...

- DNS, DHCP, IPAM, NCCM

- IPv6 Center of Excellence

- IF-Map / DNSSec

- Hiring (sales, services, support, engineering)

Page 7: Php memory-redux

who r u

Designers? Developers?

Dev-Ops? Sys-Admin?

Managers? Recruiters?

Looking? Hiring?

Page 8: Php memory-redux

follow along

https://github.com/nanderoo/php-memory-redux.git

Page 9: Php memory-redux

overview

Let us cover 3 things:

1) Streams and filters overview

2) php://memory & php://temp

3) Demo - word/letter frequency

Page 10: Php memory-redux

overview

What are streams:

- Streams are resources, a variety of protocols and wrappers: file, http, ftp, zlib, data, glob, phar, ssh2, expect...

- Lets you interact at a lower level, sockets, buffers, 3rd party libs, with other devices and systems.

Page 11: Php memory-redux

overview

What are filters:

- Code that performs actions in-situ

- As a stream is being written to or read from

- Can be stacked / combined

- Great for cutting data cruft

Page 12: Php memory-redux

overview

Out of the box filters:

- Strings (upper, lower, strip tags, rot13)

- Conversion (base64 encode / decode)

- Compression (gzip, bz2)

- Encryption (mcrypt)

Page 13: Php memory-redux

overview

More:

- You make your own with php_user_filter() and stream_filter_register()

- Predefined constants: STREAM_* and PSFS_*

- Hedge on stuff breaking that isn't your fault

Page 14: Php memory-redux

memory & temp

php://memory

and

php://temp

Page 15: Php memory-redux

memory & temp

What are they?

- Wrappers to streams, resources.

- Others: stdin, stdout, stderr

- Support stat() for low-level insight

Page 16: Php memory-redux

memory & temp

php://memory examples:

example-01.php = basic functionality

example-02.php = reading in text

example-03.php = out of memory

example-04.php = stream copy workaround

Page 17: Php memory-redux

memory & temp

php://temp examples:

example-05.php = temp w/ memory limit

example-06.php = temp

Page 18: Php memory-redux

but why

- Easy to read and write to

- Already baked in

- They said 'no' to permissions

- Performance / balance resources

Page 19: Php memory-redux

bonus demo

Frequency Analysis:

- What is 'etaon rishd' (and variants)

- Take a stream of data

- Capture letter frequency

Page 20: Php memory-redux

almost fin

Questions? Comments? Musings?

[email protected]

Page 21: Php memory-redux

oh yeah

Semaphores, Shared Memory, and IPC?

Expect, SNMP, Sockets, StatsD, or Graphite?

SurgeCon, MDC3, BSidesDC?

/dev/hell & Voices of the ElePHPant