krakjoe
Members-
Posts
10 -
Joined
-
Last visited
Contact Methods
-
Website URL
http://pthreads.org
Profile Information
-
Gender
Not Telling
krakjoe's Achievements
Newbie (1/5)
0
Reputation
-
I'll assume you got as far as executing ... pthreads objects can be shared and manipulated among contexts, the problem of sharing a list of users between threads safely is a non-problem: <?php/* Note: this example is not well synchronized, sometimes numbers and data may mismatch*/class UserList extends Stackable { public function run(){}} class UserThread extends Thread { public function __construct(UserList $shared) { $this->shared = $shared; } public function run() { while (($num = count($this->shared))) { printf("%lu finds %s users\n", $this->getThreadId(), $num); var_dump($this->shared); /* randomly remove a user so this thread has an end */ if (time() % 2 == 0) $this->shared->shift(); /* sleep is bad, but you want to read output */ sleep(1); } }} /* create a list of users */$list = new UserList(); /* fill a list of users */$list->merge(array( "harry", "barry", "sue", "sally")); /* create some threads */$threads = array();$thread = 0; while ($thread < count($list)) { $threads[$thread] = new UserThread($list); $threads[$thread]->start(); $thread++;} /* you can still manipulate the list from here */$list[] = "larry";$list[] = "carry";$list[] = "krakjoe"; /* join some threads */foreach ($threads as $thread) $thread->join();?> In the example above you can see how an object can be manipulated by all contexts at the same time, hope that makes things clearer ...
-
Just outputting expiration headers will improve the situation ... other than that you might want to think about locally caching the images rather than fetching the real location ( which I assume is cross network ) everytime ...
-
Sync Data Btwn Website, Desktop App & Mobile App?
krakjoe replied to doni49's topic in Application Design
[sry mods it cut me off, I waz scratchin me head ...] better that all this checking go on by moving around blocks of memory than seeking a disk or holding up other connections, it fits with Web2.0 see, having pages change in response to actions rather than reload/redirect - even if the write were to block the user can have a pretty animation and something colourful to look at while your solution is working, that's all they want - a bit of action ... -
$literature is an indexed array, $col => $lit roughly translates to $lit=$literature[$col] The modulus operator takes the left hand value and divides it by the right hand value, returning the remainder for evaluation, so it basically says if $col divides by 3 and leaves no remainder.
-
Sync Data Btwn Website, Desktop App & Mobile App?
krakjoe replied to doni49's topic in Application Design
Ah, brain storming, I love brain storming ... As someone said without a description of the data and it's uses our suggestions could well be just wasted words ... As it isn't mentioned I assume that you've already chosen SQL as the most suitable sort of storage and that your tables are optimized to the best of MySQL's ability... Another pivoting point of this solution is scalability, even to select one timestamp in a very well indexed table is going to incur overhead when you reach into the millions of rows. A more scalable approach might be an event table, you basicaly want to implement a kind of rwlock or mutex, so define events as such. In that if someone wants to write ( insert a write event ) they either have to wait to insert, or your logic can decipher wether will have adverse affects based on the other events in front of it in the queue ... this way the table is only as busy ( and by proxy large as fired events can be erased ) as the website up to the second or so ... depending on uses a read could "block" or not, that's entirely dependant on what the writes are doing and what they are doing it too ... but I think you'll get the gist of what I'm saying ... Also, also, consider the best place for such short lived data, personally I wouldn't go with SQL for the event table I describe because at a point that would have trouble scaling too ... I'd go for apc, or if the app has a distributed infrastructure of any kind I'd go with memcache/couchbase ... -
<?php function displayLiterature() { global $wpdb; define('COLS', 3); // number of columns $col = 0; // number of the last column filled $output = ""; $query = "SELECT * FROM literature ORDER By lit_id DESC"; $literature = $wpdb->get_results($query, ARRAY_A); if(count($literature) > 0) : printf("<table>\n"); printf("<tr>\n"); foreach($literature as $col => $lit) { printf("<td>\n"); printf("\t<img src=\"%s\" width=\"130\" height=\"170\" alt=\"thumbnail\" />\n", $lit["lit_image"]); printf("\t<a href=\"%s\" target=\"\">%s</a>\n", $lit["lit_pdf"], $lit["lit_title"]); printf("</td>\n"); if (($col % 3) == 0) { printf("</tr>\n<tr>\n"); } } printf("</tr>\n"); printf("</table>\n"); else: printf("<p>Sorry No Results</p>"); endif; } ?>
-
I know it's pretty difficult to get used too ... but look at it like this, if I hired a builder to make me a house, and I then requested them to do something that would threaten the integrity of it's structure I would not expect them to do it ... uncomfortable or not, it's a well known fact that people hate music playing or videos when they didn't request them, we have youtube for that. You should try a bit harder to impress the truth on your client in order to steer them from making the wrong decisions ... Why not show them a link to this page, experts in their field say it's the wrong thing to do, ergo, intrusive or not, it's the wrong thing to do. Just 2 cents, have fun
-
Proper forms: Using type=hidden on every input, draw the form for each item that's clickable and assign a unique id, draw a normal link around the item but href=#, then attach an event to the normal link element so that link.onclick fires form.submit. Framework only: Of course it may not be desireable for that much markup to be included in the page, in which case store the relational data ( that would be in a form ) by some other means, session, apc etc, and just use a framework and ids to attach an event to a normal link to # that creates an XHR post.
-
foreach($literature as $lit) use as $index => $lit and the modulus operator to detect when to output the </tr><tr> and move $output .= "</tr>"; // end last row $output .= "</table>"; outside loop, like so <?php $r=99; ?> <table> <tr> <th>c1</th> <th>c2</th> <th>c3</th> </tr> <tr> <?php while($r-->0){ printf("<td>%d</td>", $r); if (($r % 3) == 0){ printf("</tr><tr>"); } } ?> </tr> </table>
-
I think maybe the point was to get you to look at how to control the flow of nested loops ... public class Answer { public static void main(String argv[]) { for ( int start = 0; start <= 9; start++ ){ System.out.printf("%d", start); for ( int inner = start-1; inner>=0; inner-- ){ System.out.printf("%d", inner); } System.out.print("\n"); } } } Jessica is right, you should try to do this for yourself, at the very least make sure you understand the answer, look for ways to improve it, perhaps find another way using a different control structure ... Have fun
-
Like I said I didn't want to sign up and just start posting links, it's spammy isn't it ... then I saw another guy getting ticked off when I came back to write up an article so hesitated ... More than anything I was hoping to get a discussion about the subject going, I'm not really looking for people to look at the project as installing it right now will be server admins job as it's not on pecl yet, and I've only just got shared build working today. If someone could let me know if that's okay, to post up an article explaining the project, with a link, and ask a few questions for people to respond to in their responses, if they'd like to respond. If not it's no bother, I'm sure I'll get these opinions and your users will hear about it eventually anyway ... Sorry to cause such a fuss ...
-
I am aware of that, I would love to help out, I used to spend a lot of time helping people out on forums such as this, but I simply don't have the time ... I more just wanted to get opinions and suggestions on such a feature as the response from the php developers community is, lets say, mixed. But that's a different bunch to the users, and this seems to be the place to find users ... I don't want to break any rules and don't intend to "pimp" anything, so if you could delete my account, I guess people will hear about it in time ...
-
I wrote multi-threading for PHP ...
-
What if, I genuinely have something to say that most of the people running the board or using will want to see ??
-
Hi chaps, I've written something that some of you may think is quite cool, others will think it's against God, or whatever ... Didn't want to join up and start spamming stuff everywhere so thought I'd introduce myself and say hello: hello