GithubHelp home page GithubHelp logo

Usage of php multithreading.. about pthreads HOT 6 CLOSED

krakjoe avatar krakjoe commented on August 15, 2024
Usage of php multithreading..

from pthreads.

Comments (6)

krakjoe avatar krakjoe commented on August 15, 2024

Yes, I should think so. That is, if I understand you correctly and you have more than one PDF to stamp in a single request.

Start with the examples, all of them even if you think you are not interested in that particular part of multi-threading. They have advice too informal for the PHP manual. Then, there's the PHP manual, which is as much as makes no difference up to date ( at the moment ), and includes inline example for almost everything you need to use. Then when you have read all that, there's bug reports that have been filed and my responses, and solutions to them. After all that, there's me, feel free to contact me directly.

from pthreads.

Xebur13 avatar Xebur13 commented on August 15, 2024

How can I contact you :) Sorry, a new github user here.. Couldn't found any way to send you message..

The system basically is:

function1 -> sends info to plugin1 -> receives info from plugin1 (function2 waits until function 1 finished this process)
function2 -> sends info to plugin2 -> receives info from plugin2 (function3 waits...)
..
..

I've 13 functions like that and it takes 3-4 seconds for the plugin to stamp each pdf file. So in total it takes 25-30 seconds and it's way too long.

from pthreads.

krakjoe avatar krakjoe commented on August 15, 2024

You're contacting me now !!!

You can email pthreads at the pthreads website dot org too ...

from pthreads.

Xebur13 avatar Xebur13 commented on August 15, 2024

if ($tarih_sql == true)
{
$urun_id = $db->VeriCek($Id, 'siparisler', 'urun_id');

                $pdf_url = $ykd->PdfGen($Id);

                $urun_pdf_url2 = $db->VeriCek($urun_id, 'urunler', 'pdf_url2');
                    if ($urun_pdf_url2 != '') { $pdf_url2 = $ykd->PdfGen2($Id, '0', '2'); $pdf_url_sql .= ", pdf_url2='$pdf_url2'"; }

                $urun_pdf_url3 = $db->VeriCek($urun_id, 'urunler', 'pdf_url3');
                    if ($urun_pdf_url3 != '') { $pdf_url3 = $ykd->PdfGen3($Id, '0', '3'); $pdf_url_sql .= ", pdf_url3='$pdf_url3'"; }

                $urun_pdf_url4 = $db->VeriCek($urun_id, 'urunler', 'pdf_url4');
                    if ($urun_pdf_url4 != '') { $pdf_url4 = $ykd->PdfGen4($Id, '0', '4'); $pdf_url_sql .= ", pdf_url4='$pdf_url4'"; }

                $urun_pdf_url5 = $db->VeriCek($urun_id, 'urunler', 'pdf_url5');
                    if ($urun_pdf_url5 != '') { $pdf_url5 = $ykd->PdfGen5($Id, '0', '5'); $pdf_url_sql .= ", pdf_url5='$pdf_url5'"; }

..
..
..

This is the sample of the code that causes delays. For the offline purchases if I click "approve" from the admin panel, it directly sends the first pdf the the PdfGen function (which is posting customer details to wordpress plugin, and receives the stamped pdf's url back)

The code controls in the "if statements" whether there is more than one pdf or not. If there's, it sends it to a different function PdfGen2 (that posts the info to a second plugin installed in another directory)

The problem is stamping in the plugin takes 3-4 second and each if statement waits that time to start controlling whether there is another pdf and if yes posting it to the plugin..

Can multithreading be used to send all the pdf's to the post functions at the same time? Without waiting each other to end? If yes, how?

from pthreads.

krakjoe avatar krakjoe commented on August 15, 2024

Each function appears to depend on the last function having run.

from pthreads.

chibisuke avatar chibisuke commented on August 15, 2024

It might be possible depending on the internals

from my understanding this part of the code:

                $urun_pdf_url2 = $db->VeriCek($urun_id, 'urunler', 'pdf_url2');
                    if ($urun_pdf_url2 != '') { $pdf_url2 = $ykd->PdfGen2($Id, '0', '2'); $pdf_url_sql .= ", pdf_url2='$pdf_url2'";

is not dependent on the runs of the others, so it could run in a thread. But in the end it depends on what $ykd is and how it works internally.

The simple rule to follow there is: you should not attemp to share a database connection or any other kind of resource. And since simple DB checks are usualy fast, you can just do all that checks before you spawn the threads.

from pthreads.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.