Upgrade to PRO for Only $50/Year—Limited-Time Offer! 🔥

Lone Star PHP 2017 - More Than Just a Hammer

Lone Star PHP 2017 - More Than Just a Hammer

Learn to expand beyond just PHP to integrate other languages into both your personal skill set and the solutions you deliver.

In this talk we'll cover integrating JavaScript (frontend and backend via node) and how you can expand your current skill set to include this or any other language alongside PHP. The old saying, if all you have is a hammer everything looks like a nail, is very true so let's learn how to use a wrench and maybe a chainsaw!

Not only will this give you another tool in your tool belt, it will give you a greater understanding of development practices and the ability to on new jobs, new projects, and new challenges.

Ben Edmunds

April 22, 2017
Tweet

More Decks by Ben Edmunds

Other Decks in Technology

Transcript

  1. RPC / APIs JSON-RPC (client) —> (server) {"jsonrpc": "2.0", "method":

    "sendNotification", "params": {"id": 123, "sender_id": 1}, "recipient_id": 2, "message": "yo"} (client) <— (server) {"jsonrpc": "2.0", "result": 1, "id": 123}
  2. Databases / Redis Column | Type ----------------------------+--------------------- id | integer

    accepted_datetime | timestamp without time zone processed_datetime | timestamp without time zone
  3. MQ Example Install the RabbitMQ server on Mac OS $

    brew install rabbitmq $ echo 'export PATH=/usr/local/sbin:$PATH' >>~/.bash_profile Append to your path $ rabbitmq-server Start the server
  4. MQ Example { "require": { "php-amqplib/php-amqplib": ">=2.6.1" } } $

    composer install Create and edit composer.json Install packages
  5. MQ Example … $connection = new AMQPStreamConnection( 'localhost', 5672, 'guest',

    'guest'); $channel = $connection->channel(); $channel->queue_declare( 'notifications', false, true, false, false ); Edit sendNotification.php
  6. MQ Example … $notification = [ 'id' => microtime(), 'sender_id'

    => Auth::user()->id, 'recipient_id' => $recipientUser->id, 'message' => 'yo' ]; $msg = new AMQPMessage(json_encode($notification)); $channel->basic_publish($msg, '', 'notifications'); Edit sendNotification.php
  7. MQ Example Check our queue for data $ rabbitmqadmin get

    queue=notifications +---------------+----------+---------------+------------------------------------------------- | routing_key | exchange | message_count | payload +---------------+----------+---------------+------------------------------------------------- | notifications | | 0 | {"sender_id":1,"recipient_id":2,"message":"yo"} +---------------+----------+---------------+-------------------------------------------------
  8. MQ Example { "dependencies": { "amqplib": "0.5.1" } } $

    npm install Create and edit package.json Install packages
  9. MQ Example console.log('[*] Waiting for notifications'); ch.consume(queueName, function(msg) { ch.ack(msg);

    console.log("[x] Received %s", msg.content.toString()); }); Edit processNotifications.js
  10. MQ Example $ php sendNotification.php Run our PHP script Output

    from Node [*] Waiting for notifications [x] Received {"id":"0.36937600 1492376196", "sender_id": 1,"recipient_id":2,"message":"yo"}
  11. Direct Exec Example Setup repo $ mkdir directProject && cd

    directProject Create modules dir $ mkdir modules
  12. Direct Exec Example <html><body> <h1>Make sure this field is required

    and says "yo"</h1> <input type="text" name="thing" id="thing" /> <input type="button" value="Validate!" onClick="validate()" /> <script type="text/javascript" src="modules/require.js" /> <script type="text/javascript" src="modules/index.js" /> </body></html> Create and edit index.html
  13. Direct Exec Example exports.isValidYo = function(input) { if (input ===

    'yo') { return true; } return false; }; Create and edit modules/validator.js
  14. Direct Exec Example function validate() { var validator = require('modules/validator');

    if (validator.isValidYo(document.getElementById('thing').value)) { alert("They're good YOs Brent"); } else { alert("BAD!"); } } Create and edit index.js
  15. Direct Exec Example var validator = require('./modules/validator'); if (validator.isValidYo(process.argv[2])) {

    console.log('good'); process.exit(0); } else { console.log('bad'); process.exit(1); } Create and edit nodeValidator.js
  16. Direct Exec Example <?php $input = escapeshellarg($argv[1]); exec('node ./nodeValidate.js '

    . $input, $output, $result); if ($result === 0) { echo ""; } else { echo ""; } Create and edit phpValidate.php
  17. Q/A