/    Sign up×
Community /Pin to ProfileBookmark

[RESOLVED] PHP sockets, multithreading?

I am currently in the process of converting a C# application to PHP.

Within this application I have a multithreaded loop that handles incoming packets.

Since PHP does not support multithreading what would be the best way to handle these packets?

The only thing I have managed to come up with so far is to spwan another PHP script from within the first and write the incoming packets to a database that would be polled by an RPC call every X seconds.

Can this be done using PHP sockets alone?
Will I be able to store the packets within the PHP sockets for an extended amount of time insted of having to write the packets to a database?

Or is there another way?

to post a comment
PHP

3 Comments(s)

Copy linkTweet thisAlerts:
@bokehJan 17.2007 — In PHP you can open and read from sockets in non-blocking mode. That means you could open, for example, ten connections in a loop and send a request to each. You could then loop through them every so often (also in non-blocking mode). If you try to read from a socket in non-blocking mode and there is nothing to read at that instant PHP hands control back to the script rather than waiting (indefinately) for the socket to output something.
Copy linkTweet thisAlerts:
@NightShift58Jan 21.2007 — I've never used it...

but it seems that[code=php]declare(ticks=1);[/code]could give you a bit more (finer) control over the loops and you may not have to spawn out.
Copy linkTweet thisAlerts:
@MrCoderauthorJan 21.2007 — I've never used it...

but it seems that[code=php]declare(ticks=1);[/code]could give you a bit more (finer) control over the loops and you may not have to spawn out.[/QUOTE]


Thats nice to know, thanks!
×

Success!

Help @MrCoder spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.20,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...