wood burning stoves 2.0*
The moose likes PHP and the fly likes swing worker in php ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Languages » PHP
Bookmark "swing worker in php ?" Watch "swing worker in php ?" New topic
Author

swing worker in php ?

Georgios Chatziefstratiou
Ranch Hand

Joined: May 26, 2012
Posts: 83
Hi there


Example i have 50.000 rec and i want to export them and still access the application.I use an Api but i have try with also with sql query .

The query joins about 3 -4 tables and it takes some time. Both of them take time(a lot)!!!

in Java there is a swing worker class if you want to have something done (in background) and still access the application is there something similar in php.

I have to optimize query so on but what else can i do any ideas ?


thanks
K. Tsang
Bartender

Joined: Sep 13, 2007
Posts: 2379
    
    7

PHP has threads too similar to java. The PHP library for multi-threading is "pthreads" containing classes like Thread, Worker, Threaded etc

Have a look at the pthreads library

By the way I didn't use such library before.


K. Tsang JavaRanch SCJP5 SCJD/OCM-JD OCPJP7 OCPWCD5
Georgios Chatziefstratiou
Ranch Hand

Joined: May 26, 2012
Posts: 83
K. Tsang wrote:PHP has threads too similar to java. The PHP library for multi-threading is "pthreads" containing classes like Thread, Worker, Threaded etc

Have a look at the pthreads library

By the way I didn't use such library before.



what have you use then ?How can i optimized the Api or the Query now is 50000 tomorrow is 150000 . Any ideas ?
K. Tsang
Bartender

Joined: Sep 13, 2007
Posts: 2379
    
    7

For the query optimization, look into adding indexes. But first try to get an execution plan of the sql from the database using the "explain" command.

What database are you using? If MySQL have a look at here for more info.
Georgios Chatziefstratiou
Ranch Hand

Joined: May 26, 2012
Posts: 83
K. Tsang wrote:For the query optimization, look into adding indexes. But first try to get an execution plan of the sql from the database using the "explain" command.

What database are you using? If MySQL have a look at here for more info.

yes i use Mysql and i have already look "explain " something else?
K. Tsang
Bartender

Joined: Sep 13, 2007
Posts: 2379
    
    7

Going back to the very beginning. You mentioned you are joining 3-4 tables. 50K records becomes 150K? How are you joining the tables? left join, inner join

Since you gone over the explain optimization stuff, I suppose you have taken action with the suggestions from the execution plan.

You plan to export the data but doing "all" records (eg 50K+) in one go is indeed disk I/O intensive. Doing this in chunks would probably improve the performance.

Furthermore, you should know the data size of each record (export a multiple factor) should again improve.

Lastly partitioning table by date or something may be possible.

Your issue is more of a database issue rather than PHP.
Georgios Chatziefstratiou
Ranch Hand

Joined: May 26, 2012
Posts: 83
K. Tsang wrote:Going back to the very beginning. You mentioned you are joining 3-4 tables. 50K records becomes 150K? How are you joining the tables? left join, inner join

Since you gone over the explain optimization stuff, I suppose you have taken action with the suggestions from the execution plan.

You plan to export the data but doing "all" records (eg 50K+) in one go is indeed disk I/O intensive. Doing this in chunks would probably improve the performance.

Furthermore, you should know the data size of each record (export a multiple factor) should again improve.

Lastly partitioning table by date or something may be possible.

Your issue is more of a database issue rather than PHP.



50 k maybe sometime 150k it depends mostly is 50k.

This is done by the application Api not by joining i have use the explain with a join created by me to see the difference.

I have also change "Apache" with "nginx" which has better results with the persistence Api the Application use.

I will cut the Api that i use and do it otherwise, with a function or left join which as i have seen was very fast .

I have the results in 3 min from test .

You are right its db issue.

Thanks

K. Tsang
Bartender

Joined: Sep 13, 2007
Posts: 2379
    
    7

Great you found the root cause.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: swing worker in php ?