Pro Functional PHP Programming Application Development Strategies for Performance Optimization, Concurrency, Testability, and Code Brevity Aley instant download
Pro Functional PHP Programming Application Development Strategies for Performance Optimization, Concurrency, Testability, and Code Brevity Aley instant download
https://textbookfull.com/product/pro-functional-php-programming-
application-development-strategies-for-performance-optimization-
concurrency-testability-and-code-brevity-rob-aley/
https://textbookfull.com/product/biota-grow-2c-gather-2c-cook-
loucas/
https://textbookfull.com/product/pro-typescript-application-
scale-javascript-development-second-edition-fenton/
https://textbookfull.com/product/pro-typescript-application-
scale-javascript-development-2nd-edition-steve-fenton/
Functional Python Programming: Use a functional
approach to write succinct, expressive, and efficient
Python code, 3rd Edition Lott
https://textbookfull.com/product/functional-python-programming-
use-a-functional-approach-to-write-succinct-expressive-and-
efficient-python-code-3rd-edition-lott/
https://textbookfull.com/product/mastering-php-design-patterns-
develop-robust-and-reusable-code-using-a-multitude-of-design-
patterns-for-php-7-ali/
https://textbookfull.com/product/ecosystem-management-adaptive-
strategies-for-natural-resources-organizations-in-the-twenty-
first-century-aley/
https://textbookfull.com/product/clean-code-with-c-second-
edition-refactor-your-legacy-c-code-base-and-improve-application-
performance-using-best-practices-alls/
https://textbookfull.com/product/programming-php-4th-edition-
peter-macintyre/
Rob Aley
While the advice and information in this book are believed to be true
and accurate at the date of publication, neither the authors nor the
editors nor the publisher can accept any legal responsibility for any
errors or omissions that may be made. The publisher makes no
warranty, express or implied, with respect to the material contained
herein.
Chapter 1:Introduction
Further Reading
PHP Versions
Conclusion
Examining State
Further Reading
What Is a Function?
Named Functions
Variable Functions
Language Constructs
Return Values
Lambda/Anonymous Functions
Higher-Order Functions
Scope
Further Reading
State
Further Reading
Closures
Side Effects
Referential Transparency
Pure Functions
Further Reading
Conclusion
Recursive Functions
Basic Recursion
Partial Functions
Functional Expressions
Functional Composition
Conclusion
Currying Functions
What Is a Monad?
Monad Axioms
Monad Axiom 1
Monad Axiom 2
Monad Axiom 3
The IO Monad
Learn More About Monads
Further Reading
Recursive Lambdas
Type Declarations
Further Reading
Summary
Measuring Performance:Profiling
Manual Profiling
Profiling Tools
Low-Level Profiling
Further Reading
Memoization
Further Reading
Further Reading
Generators
Further Reading
Parallel Programming
Multithreaded Programming
Further Reading
Further Reading
Conclusion
Event-Based Programming
Further Reading
Asynchronous PHP
Further Reading
Further Reading
Inline Impurities
Summary
Pramda
Phamda
Underscore.php (1)
Underscore
Underscore.php (2)
Miscellaneous Libraries
Saber
Functional PHP
Other Libraries
Introducing Hadoop
About MapReduce
Installing Hadoop
Tools
Further Reading
Chapter 10:Afterword
Where to Now?
Microsoft Windows
macOS/OS X
Linux/Unix
Further Reading
Tools
Composer
Symfony2 Bundles
Getting Help
Stack Overflow
Other Books
Newsgroups
PHP Subredit
PHP on GitHub
Office Documents
Graphics
Audio
Miscellaneous
Further Reading
Further Reading
From a File
From a String
From STDIN
Further Reading
Windows php-win.exe
Further Reading
Further Reading
Further Reading
Further Reading
PHP REPLs
PsySH
Boris
phpa
PHP Interactive
Sublime-worksheet
phpsh
iPHP
Articles
Online Books
Videos
Online Courses
Data Structures
Mutability in PHP
Functional Composition
Monads
Types
Profiling
Memoization
Lazy Evaluation
Parallel Programming
Testing
Event-Based Programming
Asynchronous PHP
Big Data/Hadoop
General-Purpose Libraries
Functional Framework
Lisp in PHP
Index
Contents at a Glance
About the Author
Acknowledgments
Chapter 1:Introduction
Chapter 10:Afterword
Index
About the Author and About the
Technical Reviewer
About the Author
Rob Aley
I’ve been programming in PHP since late
2000. Initially it wasn’t by choice because my
preferred languages at the time were Perl
and Delphi (also known as Object Pascal).
Things began to change after I graduated
from the University of Leeds with a degree in
computer science in 1999 and started out in
a career as a freelance web developer. After
only a couple of months I was offered the
opportunity to take over a (relatively
speaking) substantial government web site
contract from a friend who was exiting the
freelance world for the safer and saner world of full-time
employment. The only catch was that several thousand lines of code
had already been written, and they were written in a relatively new
language called PHP. Oh, and the only other catch was that I had
about a week to learn it before taking over the site. So, as was the
way at the time, I popped down to the local Waterstones bookshop.
(For the younger among you that’s where we used to get books. And
we had to go out and get them. Or order online and wait many days
for them to be delivered.) With my paper copies of The Generic
Beginner’s Complete Guide to PHP and MySQL for Dummies
Compendium (I may not have recalled the titles completely
correctly), I settled down with a pint of ale (I’m in Yorkshire at this
point, remember) and set about reading them. A few days later I
was coding like a pro (well, stuff was working), and 17 years later I
haven’t looked back. Over those 17 years PHP has changed vastly
(the source code for the government web site I mentioned was
littered with comments like “# Would have used a foreach here, if
PHP had one…”) and so have I. I like to think that both I and PHP
have only improved and matured over the years.
After a varied career as a freelancer and starting up a couple of,
er, startups (IT related and not) with varying (usually dismal)
success, I spent the past ten years as a programmer at the
University of Oxford. My day job involved performing medium-scale
data acquisition and management, doing statistical analysis, and
providing user interfaces for researchers and the public. The
majority of my development work was done in PHP, either
developing new projects or gluing together other people’s software,
systems, and databases. I’ve recently left the university to
concentrate on writing books like this and providing consulting and
training (in PHP, information governance, and related areas). But I’m
still programming in PHP!
Throughout my career I’ve always used PHP for web
development, but for desktop GUI work I initially used Delphi (and
then Free-Pascal/Lazarus), complemented with Bash shell scripting
for CLI-based tasks. This was mainly because I learned them while
at university. However, as PHP has matured, I’ve increasingly used it
beyond the Web, and now I rarely use anything else for any
programming or scripting task I encounter. Having been immersed in
other languages such as C++, JavaScript, Fortran, and Lisp (and
probably others that my brain has chosen deliberately not to
remember) by necessity during university and in some of my
freelance jobs, I can honestly say that PHP is now my language of
choice, rather than of necessity. At university (in the late 1990s) I
took a couple of classes that involved functional programming, but
at the time I really didn’t “get the point.” It’s only in recent years
that I’ve picked up functional-style programming again, partly
because of the “buzz” that’s developed around it and partly because
as my programming styles have “matured,” I’ve seen the advantages
to functional coding.
When I’m not tied to a computer, I would like to say I have lots
of varied and interesting hobbies. I used to have. I could write a
whole book (which wouldn’t sell well) about where I’ve been and
what I’ve done, and I’d like to think it’s made me a well-rounded
person. But these days I don’t have any. In large part, this is
because of the demands of my three gorgeous young daughters,
Ellie, Izzy, and Indy; my gorgeous wife, Parv; and my even more
gorgeous cat, Mia. And I wouldn’t have it any other way. That’s what
I tell myself, anyway….
—Rob Aley
1. Introduction
Rob Aley1
(1) Oxford, UK
SELECT forename,
Surname
FROM users
<?php
require_once('image_functions.php');
require_once('stats_functions.php');
require_once('data_functions.php');
$csv_data = file_get_contents('my_data.csv');
$chart = make_chart_image (
generate_stats
(
data_to
_array (
$csv_data
);
file_put_contents('my_chart.png', $chart);
CHAPTER XXVII.
CHAPTER XXVIII.
Without taking the time to peruse the letters that were handed him,
Don Sancho concealed them in his doublet, and proceeded hastily to
his sister's apartment.
She was anxiously awaiting him.
"Here you are at last, brother," she exclaimed on perceiving him.
"What," the young man replied, as he kissed her hand, "were you
expecting me?"
"Oh, yes, that I was; but you are very late—what has kept you so
long?" she asked, in agitation.
"Where have I been? Why, s'death! I have been hunting, the only
pleasure allowed a gentleman in this horrible country."
"What, at this hour?"
"Zounds, my dear Clara, a man gets home when he can, especially
in this country, where we ought to feel very happy at reaching home
again at all."
"You are speaking in enigmas, brother, and I do not at all
understand you; be kind enough, therefore, to explain yourself
clearly—have you fallen into bad company?"
"Yes, and very bad, too; but forgive me, my dear Clara, if you have
no objection, let us proceed regularly. You desired to see me
immediately on my return, and here I am at your orders; be kind
enough, therefore, to tell me how I can possibly be of service to
you, and then I will narrate the series of singular events with which
my today's sport has been diversified. I will not hide from you that I
have certain questions to ask of you, and certain explanations, which
I feel sure you will not refuse to give me."
"What do you mean, Sancho?"
"Nothing at present; do you speak first, sister."
"Well, if you insist on it—"
"I do not insist at all, sister—I only request it."
"Very good, I yield to your request; I have received several letters."
"So I have; but I confess that I have not read them yet, and do not
think they are of any great importance."
"I have read mine, and do you know what they tell me beside other
news?"
"Indeed, no, unless it be my appointment to the post of Alcade
Mayor of Hispaniola, which, I allow, would greatly surprise me," he
said, laughingly.
"Do not jest so, Sancho; the matter is very serious."
"Really? In that case speak, little sister. You see I have as solemn a
face as your dear husband."
"It is exactly to him I refer."
"Stuff! My brother-in-law? Has any accident happened to him in the
performance of his noble and wearisome duties?"
"No, on the contrary, he is in better health than usual."
"In that case, all the better for him; I wish him no harm, though he
is the most fastidious gentleman of my acquaintance."
"Will you listen to me—yes or no?" she asked, impatiently.
"Why, I am doing so, dear sister."
"You are really insupportable."
"Come, do not be angry—I have done; I will not laugh anymore."
"Have you seen the two Fifties encamped in front of the hatto?"
"Yes, and I must allow that I was greatly surprised to see them."
"You will be much more surprised on hearing that my husband is
coming here."
"He? Impossible, sister! He did not say a word to me about the
journey."
"Because it is secret."
"Ah, ah!" the young man remarked, with a frown; "And are you sure
that he is coming?"
"Certain. The person who writes me so was present at his departure,
which no one suspects; the courier who brought me the news, and
to whom the greatest diligence was recommended, is only a few
hours ahead of him."
"This is, indeed, serious," the young man muttered.
"What is to be done?"
"S'death!" the young man replied, carelessly, but gazing fixedly at
Doña Clara—"Welcome him."
"Oh!" the lady exclaimed, twisting her hands despairingly, "I have
been betrayed—he is coming to avenge himself!"
"Avenge himself? For what, sister?"
She gave him a look of strange significance, and then bent over him.
"I am ruined, brother," she said, in a hollow voice, "for this man
knows everything, and will kill me."
Don Sancho, in spite of himself, was affected by this sorrow; he
adored his sister, and felt ashamed of the part he was playing at this
moment before her.
"And I, too, Clara," he said to her, "know everything."
"You! Oh, you are jesting, brother."
"No, I am not; I love you, and wish to save you, even if I gave my
life to do so: hence, reassure yourself, and do not fix upon me eyes
haggard with grief."
"What do you know, in heaven's name?"
"I know that which probably a traitor, as you called him, has sold to
your husband, that is to say, that you left the hatto, went aboard a
vessel, which conveyed you to Nevis, and there—"
"Oh! Not a word more, brother," she exclaimed as she fell into his
arms; "you are really well informed, but I swear to you, brother, in
the name of what is most sacred in the world, that, although
appearances condemn me, I am innocent."
"I know it, sister, and never doubted it; what is your intention, will
you await your husband here?"
"Never, never! Did I not tell you he would kill me?"
"What is to be done then?"
"Fly, fly without delay; at once."
"But where shall we go?"
"How do I know? To the cliff or the forest, live among the wild
beasts sooner than remain any longer here."
"Very good, we will go, I know where to take you."
"You?"
"Yes, did I not tell you that sundry accidents happened to me today
while hunting?"
"So you did; but what has that to do with it?"
"A great deal," he interrupted; "the Major-domo, who accompanied
me, and I tumbled over an encampment of filibusters."
"Ah," she said, turning paler than she had been before.
"Yes, and I intend to conduct you to that encampment; besides, one
of the buccaneers entrusted me with a message for you."
"What do you mean?"
"Exactly what I am saying, sister."
She appeared to reflect for an instant, and then turned resolutely to
the young man.
"Well, be it so, brother, let us go to those men, though they are
represented as so cruel; perhaps every human feeling has not been
extinguished in their hearts, and they will take pity on me."
"When shall we go?"
"As speedily as possible."
"That is true, but the hatto is probably watched and the soldiers
have doubtless secret orders, you may be a prisoner without
suspecting it, my poor sister; for what other reason would the two
Fifties be here?"
"Oh! In that case I am lost."
"Perhaps there is one way, and the orders given doubtless only
affect you; but unfortunately the journey will be long, fatiguing, and
beset with numberless perils."
"What matter, brother? I am strong, do not be anxious about me."
"Very good, we will try; you are absolutely determined on flight?"
"Yes, whatever may befall me."
"Well then, we will put our trust in heaven, wait for me a moment."
The young man left the room and returned a few minutes later,
bearing a rather large bundle under his arm.
"Here are my page's clothes, I do not know how they happen to be
in my possession, but my valet probably placed them in my
portmanteau by mistake, for they are new, and I remember that the
tailor brought them home a few minutes before my departure from
Saint Domingo, but I thank accident for causing it to be so. Dress
yourself, wrap yourself up in a cloak, put this hat on your head, I will
answer for everything. Besides, this costume is preferable to your
woman's clothes for crossing the savannah; mind and not forget to
place these pistols and this dagger in your belt, for there is no
knowing what may happen."
"Thanks brother! I shall be ready in a quarter of an hour."
"Good; during that time I will go and reconnoitre; do not open the
door to anyone but me."
"You may depend upon me."
The young man lit a cigarette and left the apartment with the most
careless air he could assume.
On entering the zaguán, the Count found himself face to face with
the Major-domo. Señor Birbomono had such an anxious look that it
did not escape Don Sancho; still he continued to advance,
pretending not to notice it.
But the Major-domo came straight up to him.
"I am glad to meet you, Excellency," he said, "if you had not come
within ten minutes, I should have knocked at the door of your
apartment."
"Ah!" Don Sancho observed, "What pressing motive was there to
urge you to such a step?"
"Is your Excellency aware of what is taking place?" the Major-domo
continued, without appearing to notice the young man's ironical
tone.
"What! Is there really anything happening?"
"Does not your Excellency know it?"
"Probably not, as I ask you; after all, as the news, I am sure,
interests me but very slightly, you are quite at liberty not to tell it to
me."
"On the contrary, Excellency, it interests you as well as all the
inhabitants of the hatto."
"Oh! oh! What is it then?"
"It appears that the commander of the two Fifties, has placed
sentries all round the hatto."
"Very good, in that case, we need not fear being attacked by the
buccaneers, of whom you are so afraid, and I will thank the
commandant for it."
"You are at liberty to do so, Excellency, but I fancy you will find it
difficult."
"Why so?"
"Because orders are given to let anyone enter the hatto but nobody
leave it."
A shudder ran through the young man's veins on hearing this; he
turned frightfully pale, but recovering himself almost immediately,
remarked carelessly,
"Stuff! that order cannot affect me."
"Pardon me, Excellency, it is general."
"In that case, you think that, if I tried to go out—"
"You would be stopped."
"Confound it, that is very annoying, not that I have any intention of
going out, but as by my character, I am very fond of doing things
which are prohibited—"
"You would like to take a walk, I suppose, Excellency?"
Don Sancho looked at Birbomono, as if trying to read his thoughts.
"And suppose such were my intention?" he resumed presently.
"I would undertake to get you out."
"You?"
"Yes, I; am I not the Major-domo of the hatto?"
"That is true; thus, the prohibition does not extend to you?"
"To me, as to the rest, Excellency; but the soldiers do not know the
hatto as I know; I could Slip between their fingers, whenever I
liked."
"I have strong inclination to try it."
"Do so, Excellency; I have three horses at a spot where no one but
myself could find them."
"Why, three horses?" the young man asked, pricking up his ears.
"Because, doubtless, you do not wish to ride with me only, but will
take someone with you."
Don Sancho, understanding that the Major-domo had penetrated his
thoughts, made up his mind at once.
"Let us play fairly," he said, "can you be faithful."
"I am so, and devoted too, Excellency, as you have a proof."
"What assures me that you are not laying a trap for me?"
"With what object?"
"That of obtaining a reward from the Count."
"No, Excellency, no reward would induce me to betray my mistress; I
may be anything you please, but I love Doña Clara, who has always
been kind to me, and has often protected me."
"I am willing to believe you, and indeed have no time to discuss the
point, but here are my conditions: a bullet through the head if you
betray me, a thousand piastres if you are faithful; do you accept
them?"
"I do, Excellency, the thousand piastres are gained."
"You know that I do not threaten in vain."
"I know you."
"Very good, what must we do?"
"Follow me, that is all; our flight will be most easy, for I prepared
everything on my return; I had my suspicions on seeing those
demons of soldiers, suspicions which were soon changed into
certainty, after some skilful inquiries here and there; my devotion to
my mistress rendered me clear sighted, and you see that I acted
wisely in taking my precautions."
The accent with which the Major-domo pronounced these words,
had such a stamp of truth, his face was so frank and open, that the
young Count's last suspicions were dissipated.
"Wait for me," he said, "I will go and fetch my sister."
And he hurried away.
"Oh!" said Birbomono, with a grin, so soon as he was alone, "I do
not know whether Señor don Stenio de Bejar will be pleased at
seeing his wife escape in this way, when he felt so certain of holding
her; poor señora! She is so good to us all, that it would be infamous
to betray her, and then, after all, this is a good deed which brings
me one thousand piastres," he added, rubbing his hands, "that is a
very decent amount."
It was about eleven o'clock at night, all the lights in the hatto were
extinguished by orders of the Major-domo, who had provided for
everything; the slaves had been dismissed to their huts, and a
solemn silence brooded over the landscape, a silence solely
interrupted at regular intervals, by the sentries who challenged each
other in a monotonous voice.
Don Sancho soon returned, accompanied by his sister, wrapped up
like himself, in a long mantle.
Doña Clara did not speak, but on joining the Major-domo, she
gracefully held out her right hand to him, on which he respectfully
impressed his lips.
Although the officers had told the soldiers to keep a good guard, and
watch carefully, not only the hatto, but its environs, the latter,
slightly reassured by the darkness on one hand, and on the other, by
the gloomy and mysterious depths of the forests that surrounded
them, stood motionless behind the trees, contenting themselves with
responding to the challenge, every half hour, but not venturing to go
even a few yards from the shelter they had chosen.
The reasons for this apparent cowardice, were simple, and although
we have explained them, we will repeat them here, for the sake of
greater clearness.
In the early times of the buccaneers landing on Saint Domingo, the
Fifties sent by the governor in pursuit of them, were armed with
muskets; but after several encounters with the French, in which the
latter gave them an awful thrashing, their terror of the adventurers
became so great that, whenever they were sent on an expedition
against these men, whom they almost regarded as demons, no
sooner did they enter the forests, or the mountain gorges, or even
the savannahs, where they might suppose the buccaneers to be
ambushed, than they began to fire their pieces right and left, for the
purpose of warning the enemies, and inducing them to withdraw.
The result of this clever manoeuvre was that the adventurers, thus
warned, decamped in reality, and thus became intangible; the
governor noticing this result, eventually guessed its cause, and
hence, in order to avoid such a thing in future, he took the muskets
away from the soldiers and substituted lances. This change, let us
hasten to add, was not at all to the liking of these brave soldiers,
who thus saw their ingenious scheme foiled, and were even more
exposed to the blows of their formidable enemies.
It was almost without being obliged to take any other precaution
than that of walking noiselessly and not speaking, that the Major-
domo and the two persons he served as guide, succeeded in quitting
the hatto on the opposite side to that on which the Fifties had
established their bivouac.
Once the line of sentries was passed, the fugitives hurried on more
rapidly, and soon reached a thicket in the midst of which three fully
accoutred horses were so thoroughly hidden that unless known to be
there, it would have been impossible to find them; for a greater
precaution, and to prevent them from neighing, the Major-domo had
fastened a cord round their nostrils.
So soon as the three were mounted, and before starting, Birbomono
turned to Don Sancho,—
"Where are we going, Excellency?" he asked.
"Do you know the spot where the buccaneers we met today are
bivouacked?" the young man replied.
"Yes, Excellency."
"Do you think you could succeed in finding the bivouac in the midst
of the darkness?"
The Major-domo smiled.
"Nothing is more easy," he said.
"In that case lead us to those men."
"Very good; but, Excellency, be good enough not press your horse
on at present, for we are still near the house, and the slightest
imprudence would be sufficient to give an alarm."
"Do you think, then, that they would venture to pursue us?"
"Separately, certainly not; but as they are so numerous, they would
not hesitate; the less so, because from what I heard them say, they
feel certain that the buccaneers have never come into these parts.
This redoubles their bravery, and they would perhaps not be sorry to
furnish a proof of it at our expense."
"Excellent reasoning; regulate our pace, therefore, as you think
proper, and we will only act in accordance with your judgment."
They set out; with the exception of the precautions they were
obliged to take not to be discovered, the journey had nothing
disagreeable about it, on a bright and perfumed night, beneath a sky
studded with brilliant stars, and in the midst of a most delightful
scenery, whose slightest diversities the transparency of the
atmosphere allowed to be seen.
After an hour spent in a moderate trot, their pace became insensibly
more rapid, and the horses growing gradually more excited,
eventually broke into a gallop, at which their riders kept them for a
considerable period.
Doña Clara bent over her horse's neck, and with her eyes eagerly
fixed ahead, seemed to upbraid the slowness of this ride, which,
however, had assumed the headlong speed of a pursuit: at times she
leant over to her brother, who constantly kept by her side, and asked
him in a choking voice—
"Shall we soon arrive?"
"Yes, have patience, sister," the young man said, suppressing a sigh
of pity for the agony which preyed on his sister's heart.
And their pace grew more rapid than ever.
The stars were already expiring in the heavens, the atmosphere was
growing refreshed, the horizon was striped by long mother-o'-pearl
coloured bands, a light sea breeze brought up to the travellers its
alkaline odours, and the night had passed. Suddenly, at the moment
when the three riders were about to emerge from a thick wood, in
which they had been following a track made by the wild cattle for
nearly an hour, the Major-domo, who was a few yards ahead, pulled
up his horse and leant back.
"Stop, in Heaven's name!" he exclaimed, in a low voice.
The young couple obeyed, though they did not comprehend this
order.
The Major-domo went up to them.
"Look!" he muttered, and stretched out his arm toward the
savannah.
A rapid gallop, that drew nearer every second, but which the noise
of their own march had prevented them from hearing, now smote
their ears, and almost at the same moment they saw through the
screen of foliage which hid them from sight, several horsemen pass
as if borne along by a hurricane.
A branch struck off the hat of one of the riders as he passed.
"Don Stenio!" Doña Clara exclaimed in horror.
"Zounds!" Don Sancho said, "We were just in time."
CHAPTER XXIX.
EVENTS ACCUMULATE.
Our website is not just a platform for buying books, but a bridge
connecting readers to the timeless values of culture and wisdom. With
an elegant, user-friendly interface and an intelligent search system,
we are committed to providing a quick and convenient shopping
experience. Additionally, our special promotions and home delivery
services ensure that you save time and fully enjoy the joy of reading.
textbookfull.com