SlideShare una empresa de Scribd logo
1 de 36
Caffeinated PHP Kevin Schroeder Technical Consultant Zend Technologies
About me Kevin Schroeder Consultant for Zend Programmer Sys Admin Author Etc. Me!
PHP is growing in the enterprise Programmers (Millions) Part-Time Developers and Hobbyists This means that enterprise PHP developers are going to increasingly need to work with non-PHP systems and do “non-PHP things” Independent Software Vendors Corporate ITDevelopers Source:  Gartner Dec 2007, Findings – Corporate and IT Programmers Will Discover PHP's Benefits in Larger Numbers | 3  |   21-Oct-09
PHP Extensions Can handle tasks that computationally intensive Can provide integration into existing third party software Some are bundled with the standard PHP distribution, some must be downloaded separately You can write your own!! Written in C What if you are not a C programmer? …or at least, not a good one | 4  |   21-Oct-09 PHP: Past and Present
Why Use The Java Bridge? On the web PHP will do most of what you need to do, easier. Java can fill missing integration points in PHP or augment functionality The Bottom Line(s) It allows you to extend PHP without building a C-based PHP module or The PHP/Java Bridge allows you easily connect in with Java-based applications or use existing Java APIs in PHP or Allows you to port applications from Java to PHP on a part-by-part basis | 5  |   21-Oct-09
Where does the Java Bridge fit? JEE JAAS JNDI Beans J3D JMX JMS Your Java Code | 6  |   21-Oct-09
A (rough) Architecture
Installing the Java Bridge – Windows | 8  |   21-Oct-09
Installing the Java Bridge - yum For Zend Server 4 yum install br />    java-bridge-zend-pe For Zend Server 5 yum install br />    php-5.2-java-bridge-zend-server | 9  |   21-Oct-09
Installing the Java Bridge  - apt aptitude install br />   java-bridge-zend-pe | 10  |   21-Oct-09
Installing the Java Bridge - Setup Make sure to execute /usr/local/zend/bin/zendctl.sh setup-jb
Installing the Java Bridge - Configuration
How do you use it? <?php header('Content-Type: text/plain'); $system = new Java('java.lang.System'); var_dump( $system->getProperties() ); ?> Which produces: | 13  |   21-Oct-09
How do you use it? array(50) { ["java.runtime.name"]=> string(48) "Java(TM) 2 Runtime Environment, Standard Edition“ 	 ["sun.boot.library.path"]=> string(29) "/usr/jdk1.5.0_09/jre/lib/i386"  	["java.vm.version"]=> string(12) "1.5.0_09-b01"  	["java.vm.vendor"]=> string(21) "Sun Microsystems Inc."  	["java.vendor.url"]=> string(20) "http://java.sun.com/"  	["path.separator"]=> string(1) ":"  	["java.vm.name"]=> string(26) "Java HotSpot(TM) Client VM“ 	["file.encoding.pkg"]=> string(6) "sun.io“ 	["user.country"]=> string(2) "US"  	["sun.os.patch.level"]=> string(7) "unknown“ 	["java.vm.specification.name"]=> string(34) "Java Virtual Machine Specification"  Etc, etc. | 14  |   21-Oct-09
How do you use it? What did you notice? $system->getProperties() returns an object of type Properties But var_dump($system->getProperties()) displayed a PHP associative array. What does that tell us? The PHP-Java bridge will convert any Hashtable-derived object into a PHP associative array. Hashtable methods are no longer available after conversion. | 15  |   21-Oct-09
How do you use it? Conversions Integer = int Long = float String = string StringBuffer/Builder remain Java objects Java arrays are converted to PHP arrays All other objects retain their status as Java objects and can be called as such within the PHP code For example$java = new java('java.util.jar.JarFile','me.jar');$entry = $java->getJarEntry('me.txt');$attributes = $entry->getAttributes(); | 16  |   21-Oct-09
Use Case #1 - Printing Using the Java Bridge does not just mean running simple Java classes in PHP There are several technologies available in the Java stack that could benefit you Printing is one…
Printing to JPS from PHP Part of the javax package Prints using the Java2D interface or via java.awt.print
Creating a JPS abstraction layer Code in com.zend.Printer
Adding printer support to the Java Bridge Edit the file /usr/local/zend/etc/watchdog-jb.ini
Adding printer support to the Java Bridge Restart the Java Bridge server
Let’s look at some code
Case #2 – Object Serialization Serialization is the process of transforming data into a format that can be transferred across a network PHP does serialization really well PHP NEEDS to do serialization really well Java doesn’t do, or need to do, extensive serialization Any Java object that implements the java.io.Serializable interface can be stored as a string
Object Serialization – Serializing to PHP To store the entire Java object each property must implement java.io.Serializable Serialization should occur before a shutdown hook. It may work beforehand, but don’t count on it Therefore, explicitly serialize your object ZF app dispatchLoopShutdown() is a good place if you are serializing to a session variable
Let’s look at some code
Case #3 – JMS Integration JMS = Java Messaging System (not the creator of Babylon 5) It is an API for sending messages (data)  (very) loosely coupled Asynchronous or synchronous
Step 1 – Set up a JMS Broker We’re using ActiveMQ http://activemq.apache.org/ Download and unzip Start with a regular user bin/activemq-admin start
Step 2 – Browse to http://dev:8161/admin
Step 3 – Create a queue (or don’t)
Step 4 – Send a message (and get it)
Step 5 – View the message
Step 6 – Do it in PHP  Probably best implemented as an action helper resources.frontController.actionhelperpaths.Default_Helper = APPLICATION_PATH "/helpers“ To the CLASSPATH, add All the libraries in active-mq/lib (hint: don’t type it in by hand)
Receiving a message First need to create a helper that initializes the appropriate Java objects.  Default_Helper_Mq Receiving a message involves creating a consumer based on a topic and calling receive() Let’s look at some code!!
Receiving a message What’s this issue with how this is done? It is a blocking request Why is it done that way? Because only messages sent during the connection’s active phase are received When running in a JVM on a desktop, not  problem but since we’re running on a web site this may need some work to make it work well with your app … but we also seem to have a bug with a sort of dead-lock.  So… how do we fix it?
Debugging Debugging PHP is easy but how about Java from the Java Bridge? Add this to the watchdog-jb.ini file -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=1044 Verify that the debugger is running on port 1044 [root@localhost ~]# lsof -i -P | grep 1044 java      8256     apache    4u  IPv4  14277       TCP *:1044 (LISTEN) Create a new Remote Debug Run configuration and attach
Questions? More information can be found at http://devzone.zend.com/article/4776-PHP-and-Java-Using-Java-Print-Service-with-Zend-Server-Community-Edition (just search for “Java Print Service” on the Devzone) http://files.zend.com/help/Zend-Server/java_bridge_component.htm (or just Google “Zend Java Bridge”)

Más contenido relacionado

Último

FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhisoniya singh
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...gurkirankumar98700
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxOnBoard
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...HostedbyConfluent
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Alan Dix
 

Último (20)

FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptx
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
 

Destacado

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by HubspotMarius Sescu
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTExpeed Software
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsPixeldarts
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthThinkNow
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfmarketingartwork
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
 

Destacado (20)

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 

Caffeinated PHP Zendcon 2009 by Kevin Schroeder

  • 1. Caffeinated PHP Kevin Schroeder Technical Consultant Zend Technologies
  • 2. About me Kevin Schroeder Consultant for Zend Programmer Sys Admin Author Etc. Me!
  • 3. PHP is growing in the enterprise Programmers (Millions) Part-Time Developers and Hobbyists This means that enterprise PHP developers are going to increasingly need to work with non-PHP systems and do “non-PHP things” Independent Software Vendors Corporate ITDevelopers Source: Gartner Dec 2007, Findings – Corporate and IT Programmers Will Discover PHP's Benefits in Larger Numbers | 3 | 21-Oct-09
  • 4. PHP Extensions Can handle tasks that computationally intensive Can provide integration into existing third party software Some are bundled with the standard PHP distribution, some must be downloaded separately You can write your own!! Written in C What if you are not a C programmer? …or at least, not a good one | 4 | 21-Oct-09 PHP: Past and Present
  • 5. Why Use The Java Bridge? On the web PHP will do most of what you need to do, easier. Java can fill missing integration points in PHP or augment functionality The Bottom Line(s) It allows you to extend PHP without building a C-based PHP module or The PHP/Java Bridge allows you easily connect in with Java-based applications or use existing Java APIs in PHP or Allows you to port applications from Java to PHP on a part-by-part basis | 5 | 21-Oct-09
  • 6. Where does the Java Bridge fit? JEE JAAS JNDI Beans J3D JMX JMS Your Java Code | 6 | 21-Oct-09
  • 8. Installing the Java Bridge – Windows | 8 | 21-Oct-09
  • 9. Installing the Java Bridge - yum For Zend Server 4 yum install br /> java-bridge-zend-pe For Zend Server 5 yum install br /> php-5.2-java-bridge-zend-server | 9 | 21-Oct-09
  • 10. Installing the Java Bridge - apt aptitude install br /> java-bridge-zend-pe | 10 | 21-Oct-09
  • 11. Installing the Java Bridge - Setup Make sure to execute /usr/local/zend/bin/zendctl.sh setup-jb
  • 12. Installing the Java Bridge - Configuration
  • 13. How do you use it? <?php header('Content-Type: text/plain'); $system = new Java('java.lang.System'); var_dump( $system->getProperties() ); ?> Which produces: | 13 | 21-Oct-09
  • 14. How do you use it? array(50) { ["java.runtime.name"]=> string(48) "Java(TM) 2 Runtime Environment, Standard Edition“ ["sun.boot.library.path"]=> string(29) "/usr/jdk1.5.0_09/jre/lib/i386" ["java.vm.version"]=> string(12) "1.5.0_09-b01" ["java.vm.vendor"]=> string(21) "Sun Microsystems Inc." ["java.vendor.url"]=> string(20) "http://java.sun.com/" ["path.separator"]=> string(1) ":" ["java.vm.name"]=> string(26) "Java HotSpot(TM) Client VM“ ["file.encoding.pkg"]=> string(6) "sun.io“ ["user.country"]=> string(2) "US" ["sun.os.patch.level"]=> string(7) "unknown“ ["java.vm.specification.name"]=> string(34) "Java Virtual Machine Specification" Etc, etc. | 14 | 21-Oct-09
  • 15. How do you use it? What did you notice? $system->getProperties() returns an object of type Properties But var_dump($system->getProperties()) displayed a PHP associative array. What does that tell us? The PHP-Java bridge will convert any Hashtable-derived object into a PHP associative array. Hashtable methods are no longer available after conversion. | 15 | 21-Oct-09
  • 16. How do you use it? Conversions Integer = int Long = float String = string StringBuffer/Builder remain Java objects Java arrays are converted to PHP arrays All other objects retain their status as Java objects and can be called as such within the PHP code For example$java = new java('java.util.jar.JarFile','me.jar');$entry = $java->getJarEntry('me.txt');$attributes = $entry->getAttributes(); | 16 | 21-Oct-09
  • 17. Use Case #1 - Printing Using the Java Bridge does not just mean running simple Java classes in PHP There are several technologies available in the Java stack that could benefit you Printing is one…
  • 18. Printing to JPS from PHP Part of the javax package Prints using the Java2D interface or via java.awt.print
  • 19. Creating a JPS abstraction layer Code in com.zend.Printer
  • 20. Adding printer support to the Java Bridge Edit the file /usr/local/zend/etc/watchdog-jb.ini
  • 21. Adding printer support to the Java Bridge Restart the Java Bridge server
  • 22. Let’s look at some code
  • 23. Case #2 – Object Serialization Serialization is the process of transforming data into a format that can be transferred across a network PHP does serialization really well PHP NEEDS to do serialization really well Java doesn’t do, or need to do, extensive serialization Any Java object that implements the java.io.Serializable interface can be stored as a string
  • 24. Object Serialization – Serializing to PHP To store the entire Java object each property must implement java.io.Serializable Serialization should occur before a shutdown hook. It may work beforehand, but don’t count on it Therefore, explicitly serialize your object ZF app dispatchLoopShutdown() is a good place if you are serializing to a session variable
  • 25. Let’s look at some code
  • 26. Case #3 – JMS Integration JMS = Java Messaging System (not the creator of Babylon 5) It is an API for sending messages (data) (very) loosely coupled Asynchronous or synchronous
  • 27. Step 1 – Set up a JMS Broker We’re using ActiveMQ http://activemq.apache.org/ Download and unzip Start with a regular user bin/activemq-admin start
  • 28. Step 2 – Browse to http://dev:8161/admin
  • 29. Step 3 – Create a queue (or don’t)
  • 30. Step 4 – Send a message (and get it)
  • 31. Step 5 – View the message
  • 32. Step 6 – Do it in PHP Probably best implemented as an action helper resources.frontController.actionhelperpaths.Default_Helper = APPLICATION_PATH "/helpers“ To the CLASSPATH, add All the libraries in active-mq/lib (hint: don’t type it in by hand)
  • 33. Receiving a message First need to create a helper that initializes the appropriate Java objects. Default_Helper_Mq Receiving a message involves creating a consumer based on a topic and calling receive() Let’s look at some code!!
  • 34. Receiving a message What’s this issue with how this is done? It is a blocking request Why is it done that way? Because only messages sent during the connection’s active phase are received When running in a JVM on a desktop, not problem but since we’re running on a web site this may need some work to make it work well with your app … but we also seem to have a bug with a sort of dead-lock. So… how do we fix it?
  • 35. Debugging Debugging PHP is easy but how about Java from the Java Bridge? Add this to the watchdog-jb.ini file -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=1044 Verify that the debugger is running on port 1044 [root@localhost ~]# lsof -i -P | grep 1044 java 8256 apache 4u IPv4 14277 TCP *:1044 (LISTEN) Create a new Remote Debug Run configuration and attach
  • 36. Questions? More information can be found at http://devzone.zend.com/article/4776-PHP-and-Java-Using-Java-Print-Service-with-Zend-Server-Community-Edition (just search for “Java Print Service” on the Devzone) http://files.zend.com/help/Zend-Server/java_bridge_component.htm (or just Google “Zend Java Bridge”)

Notas del editor

  1. Demo is a manual login procedure