Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

Sergey Zhuk:
Cancelling ReactPHP Promises With Timers
Aug 31, 2017 @ 17:08:35

Sergey Zhuk has a new post to his site continuing on from a previous article about promises in ReactPHP. In this latest post he shows how you can use timers to cancel the execution of promises if their execution time grows too large.

At first, let’s refresh in memory what is Promise. A promise represents a result of an asynchronous operation. You can add fulfillment and error handlers to a promise object and they will be invoked once this operation has completed or failed. Check this article to learn more about promises.

Promise is a very powerful tool which allows us to pass around the code the eventual results of some deferred operation. But there is one problem with promises: they don’t give us much control.

He then shares the code required to make a simple "Hello world" promise and a handler for when it's cancelled. He then shows how to use the PromiseTimer functionality in ReactPHP to set a timeout on the promise instance and automatically call the cancellation event when it reaches that limit. He also includes a reminder that, in the cancellation handling of the promise it's a good idea to close out and cancel any other resources that may have been in use. The post ends with an example of how you can stack other functionality on the timeout using methods like "then" and "otherwise".

tagged: reactphp timer promise promisetimer tutorial asynchronous

Link: http://seregazhuk.github.io/2017/08/22/reactphp-promise-timers/

DevShed:
Benchmarking with the Xdebug Extension
Mar 09, 2009 @ 20:11:17

DevShed has posted their next-to-last article in their look at using XDebug in your applications - part six, a look at doing some benchmarking with functions the extension provides.

You'll be pleased to hear that the Xdebug extension comes equipped with additional functions that allow us to perform other debugging tasks, such as benchmarking PHP applications and checking in what order certain functions were called by the PHP engine. Therefore, in this sixth chapter of the series I’ll be discussing in depth how to take advantage of the benchmarking abilities offered by the Xdebug library, which rely heavily on its "xdebug_time_index()" function.

Their benchamrking example uses the xdebug_time_index function to compare the start and end times of a script. Dropping it into a method in a class makes it even easier - they call the getTime method in their Timer class to grab the latest value.

tagged: benchmark xdebug extension tutorial timer start end

Link:

Matt Curry's Blog:
Check Out These Upgrades I Made To The CakePHP DebugKit
Jan 30, 2009 @ 16:21:25

Matt Curry has posted a screencast about some of the updates that he's made to the CakePHP Debug Kit:

I’ve been doing some upgrades on the CakePHP DebugKit and wanted to share them with everyone. I figured doing a quick screencast would be faster then writing a post. Was I wrong. It took me like an hour to record this, even though the running time is just over two minutes.

Included in the updates is the ability to select a page from the History and get all of the statistics for that request (instead of just teh current page like it was before). You can grab this latest version from his page on github: http://github.com/mcurry/debug_kit/tree/master.

tagged: cakephp debugkit javascript tool framework history session timer memory

Link:

DevShed:
Comparing Files and Databases with PHP Benchmarking Applications
May 08, 2008 @ 12:58:38

DevShed is wrapping up their series looking at benchmarking your PHP applications with the third part - a look at comparing execution times of scripts that can either pull from a database or from a flat file.

This large, complex subject offers numerous possibilities for experimentation, which means that you'll surely have tons of fun creating timing systems with PHP. [...] his article, then, will be focused on evaluating different scripts that fetch sets of records, first from a database, and then from flat files.

They use the Timer class they defined in a previous part of the series and wrap it around both a database class (pulling user information from a MySQL database) and a fetch to a flat file for similar information. General exceptions are handled as a part of the resource connection class.

tagged: database file compare timer class tutorial exception benchmark

Link:

DevShed:
Using Timers to Benchmark PHP Applications
Apr 30, 2008 @ 19:31:08

DevShed has posted the second article in their series looking at benchmarking your PHP scripts. This time they look at the use of "timers" to check on script execution length.

Since you already know how to create timer functions and classes, in this tutorial, I'll create some concrete examples that show where these timing mechanisms can be applied in order to evaluate the performance of certain PHP applications.

They create a few classes that connect to a database and pull out rows (handing it off to a Result class). They use these classes in two examples - one with compression (output buffering) and one without using their Timer class to evaluate the differences.

tagged: timer benchmark application tutorial class mysql row output buffering

Link:

PHP-GTK Community Site:
Three Widgets and a Timer Class
May 31, 2007 @ 15:26:00

The PHP-GTK website has four new posts highlighting three different widgets and a Timer class to make working with delays in applications simpler:

Keep an eye on the Code Snippets section of the PHP-GTK website for more helpful tips and tricks.

tagged: timer codesnippet widget terminal dial scrolling label timer codesnippet widget terminal dial scrolling label

Link:

PHP-GTK Community Site:
Three Widgets and a Timer Class
May 31, 2007 @ 15:26:00

The PHP-GTK website has four new posts highlighting three different widgets and a Timer class to make working with delays in applications simpler:

Keep an eye on the Code Snippets section of the PHP-GTK website for more helpful tips and tricks.

tagged: timer codesnippet widget terminal dial scrolling label timer codesnippet widget terminal dial scrolling label

Link:

Spindrop.us:
Digg-style AJAX comment editing in PHP/symfony
Aug 14, 2006 @ 13:10:15

Users of the site Digg will know how the commenting works. It allows you, through a series of Ajax calls and other information, to edit the comments that you've made for a certain amount of time right on the page. It's a handy feature, and in this new posting over on Spindrop.us, they show you how to create it (with the help of symfony).

It's pretty straight forward. For all of your posted comments you check if the owner of them is viewing them within 3 minutes of posting the commen. 3 minutes is usually enough time to notice you made a typo, but if you disagree I’ll leave it to you to figure out how to adjust the code.

For example, I make a comment, realize I spelled something wrong and then I can click on my comment to edit it. Of course using AJAX means this all happens without having to reload the web page. Therefore the edits are seemingly quick. So let’s add it to any web site.

He steps you through the process, first creating the DIV for the each of the comments, then some Javascript to make it editable. He then creates a timer to monitor how long it's been since the comment to limit the editing to three minutes. Finally, the code bits to load the text from the database and to save the text back in once it's been edited.

tagged: ajax symfony digg comment editing form timer tutorial ajax symfony digg comment editing form timer tutorial

Link:

Spindrop.us:
Digg-style AJAX comment editing in PHP/symfony
Aug 14, 2006 @ 13:10:15

Users of the site Digg will know how the commenting works. It allows you, through a series of Ajax calls and other information, to edit the comments that you've made for a certain amount of time right on the page. It's a handy feature, and in this new posting over on Spindrop.us, they show you how to create it (with the help of symfony).

It's pretty straight forward. For all of your posted comments you check if the owner of them is viewing them within 3 minutes of posting the commen. 3 minutes is usually enough time to notice you made a typo, but if you disagree I’ll leave it to you to figure out how to adjust the code.

For example, I make a comment, realize I spelled something wrong and then I can click on my comment to edit it. Of course using AJAX means this all happens without having to reload the web page. Therefore the edits are seemingly quick. So let’s add it to any web site.

He steps you through the process, first creating the DIV for the each of the comments, then some Javascript to make it editable. He then creates a timer to monitor how long it's been since the comment to limit the editing to three minutes. Finally, the code bits to load the text from the database and to save the text back in once it's been edited.

tagged: ajax symfony digg comment editing form timer tutorial ajax symfony digg comment editing form timer tutorial

Link:


Trending Topics: