Jump to content


  • Content Count

  • Joined

  • Last visited

  • Days Won


Everything posted by dalecosp

  1. Can you show us the db_query function? There's no such function built into PHP, so it's likely a custom function and probably isn't doing what you want it to, either because it's broken, or because you don't understand how to use it (which could easily still be the programmer's fault if (s)he didn't document it clearly)....
  2. Perhaps I misunderstand you. What it sounds like you are saying is this: A loop is running, and for each item in the loop you call file_get_contents() on an external webpage, maybe something like this: $mail_body = file_get_contents("http://mysite.com/template_generator.php?firstname=$firstname&somevar=$variable");If that is the case, it's terribly inefficient. You need a template in memory as a variable: $mail_template = <<<EOT Dear {firstname}, Are you still interested in purchasing the {name_of_product} from our web site? Thanks, MyCompany.com EOT;You should then call str_replace on this variable with the data for each iteration of the loop. Now it sounds like *maybe* the problem is that you can't get all your data from more than one location all up front, which is also part of what I'd be doing in this sort of situation. If you can't, that is a bit of a problem. I don't freelance much, but I do need to get my convertible out of the $hop with its $hiny new engine and exhau$t $y$tem ...
  3. And the other thing is probably this: You're doing an HTTP GET to a PHP script for this? Ouch! This will at least DOUBLE your throughput: format your file a la "a template", read the file ONCE into a variable, and str_replace() the DB values into the template var.
  4. Given that this is starting to sound like I'm helping a spammer, I'm a little loath to comment; however: PHP is using a heck of a lot of overhead opening and closing a connection to the SMTP server. What you should do if you want to scale is to have PHP open a socket and speak directly to the SMTP server without opening and closing the connection for a given number of mails (which you should test against your SMTP server, you do NOT want to choke it to death). If you know how to speak SMTP, this shouldn't be too difficult.
  5. Into what table? An HTML table? A Database Table? The Dining Table? Assuming the 2nd option above (DB table), I guess, eh ... don't create a unique index? But seriously, you don't give us your DB structure, and you don't give us sample data or tell us what the data is (it appears to be an array of URLs?) ... How about this? mysql> describe xsit; +-------+---------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +-------+---------+------+-----+---------+----------------+ | id | int(11) | NO | PRI | NULL | auto_increment | | var | text | YES | | NULL | | +-------+---------+------+-----+---------+----------------+ 2 rows in set (0.00 sec) Seems like it would work with that? [edit]PS: someone will probably say "Stop using the old mysql_* functions. I agree [/edit]
  6. Well, either you posted the wrong code, or you are reading the wrong error_log | screen ouput, or you need to get some sleep... There's no call to isset() in your snippet, and no include and no require, so ... (Furthermore, your code, as posted, parses without issue...)
  7. Looks like a templating lingo, similar perhaps to Smarty ....
  8. Look quite a bit like JSON? Have you tried json_decode() on this?
  9. Have you tried adding PHP to your Google search string? I've searched my history and bookmarks, but apparently it's been too long since I found whatever it was I learned from. And I didn't bookmark it. I do have a project running using pcntl_* functions. Prepare to write more code Here's the heart of a multi-threaded "fetcher" that uses posix_getpid, pcntl_fork and pcntl_waitpid in conjunction with an external function I didn't show (systemFetchSequential(), uses fetch/wget to get urls and write them to $outpath). The function is_pid() simply returns false if the PID isn't set (probably could just use a truth check and is_int(), but I didn't and can't remember why). threaded_fetch() is limited to 10 threads by the huge if/elseif construct there; if you write more code you can have more threads. I can't recall the reason, but a switch wouldn't work according to the guy I was reading. function is_pid($n) { return ($n > 0); } //EOF function threaded_fetch( $url_array, $outpath ) { global $threads; //we get this from the calling environment if ( $threads > 10 ) die("Threaded_fetch() function cannot support more than 10 threads."); $url_chunks = array_chunk( $url_array, (ceil((count($url_array)) / $threads ))+5, true ); /* PNCTL_FORK() implementation */ $ppid=posix_getpid(); // Keep reference to the PID of the parent process $pids=array( range( 0,( $threads ) ) ); // An array to hold refrence to PIDs of child processes for ( $i = 0; $i<=$threads; $i++ ) { $pid=pcntl_fork(); // Forks a new child process and keeps refrence to its PID; if ( $pid == -1 ) { die( 'could not fork' ); } if ( !$pid ) { /* This only runs in a child process */ $pids[$i] = posix_getpid();// Get the PID of the child process break; } else { $pids[$i] = $pid; } } //for $i $active_pids = count(array_filter($pids,"is_pid")); print("Started $active_pids children to process ".count($url_chunks)." chunks of data."); /* By this time all processes, child and parent have their own copy of $pid and $pids[]*/ $current_pid=posix_getpid(); // Get the PID of the curently running process if ( $current_pid == $pids[0] ) { /* Task for child 1 */ systemFetchSequential( $url_chunks[0],"$outpath" ); exit(); } elseif ( $current_pid == $pids[1] ) { /* Task for child 2 */ systemFetchSequential( $url_chunks[1],"$outpath" ); exit(); } elseif ( $current_pid == $pids[2] ) { /* Task for child 3 */ systemFetchSequential($subpage_chunks[2],"$outpath"); exit(); } elseif ( $current_pid == $pids[3] ) { /* Task for child 4 */ systemFetchSequential( $url_chunks[3],"$outpath" ); exit(); } elseif ( $current_pid == $pids[4] ) { /* Task for child 5 */ systemFetchSequential( $url_chunks[4],"$outpath" ); exit(); } elseif ( $current_pid == $pids[5] ) { /* Task for child 6 */ systemFetchSequential( $url_chunks[5],"$outpath" ); exit(); } elseif ( $current_pid == $pids[6] ) { /* Task for child 7 */ systemFetchSequential( $url_chunks[6],"$outpath" ); exit(); } elseif ( $current_pid == $pids[7] ) { /* Task for child 8 */ systemFetchSequential( $url_chunks[7],"$outpath" ); exit(); } elseif ( $current_pid == $pids[8] ) { /* Task for child 9 */ systemFetchSequential( $url_chunks[8],"$outpath" ); exit(); } elseif ( $current_pid == $pids[9] ) { /* Task for child 10 */ systemFetchSequential( $url_chunks[9],"$outpath" ); exit(); } foreach ( $pids as $key => $val ) { //wait/exit routine pcntl_waitpid( $val, $status ); unset( $pids[$key] ); } } //EOF In this case, running this function with a $url_array will start 10 children on the server, running fetch/wget against a chunk of the $url_array until they're done.
  10. Well, you can look for yourself at http://browscap.org/ "Browser" is usually a meaningful name. You might want to use a strtok() or stristr() or similar, as there are lots of everything in the file.
  11. Well, here is an *easy* way. $client_id = openssl_random_pseudo_bytes( 64 ); Not sure it's the *best* way
  12. Correct in both assumptions. browser_type is typically "Browser", "Bot/Crawler", or "Application".
  13. You'll want to use some valid SQL for this: $select = mysql_query("SELECT "); //this won't work :-( //try this instead $movies_table = "name_of_your_table"; $query = "select no,name,price from $movies_table where price >20 order by price DESC;"; $select = mysql_query($query);
  14. Come on now friend ... it's not THAT hard //lines like these will need changed: echo "<span><a id='page_a_link' href='info5.php?page=$j'>< Prev</a></span>"; //needs phone parameter echo "<span><a href='info5.php?page=$i' id='page_a_link'>$i</a></span>"; //needs phone parameter //to this echo "<span><a id='page_a_link' href='info5.php?page=$j&phone=$phone'>< Prev</a></span>"; //has phone parameter echo "<span><a href='info5.php?page=$i&phone=$phone' id='page_a_link'>$i</a></span>"; //has phone parameter //At the top, because you're only POSTing the first time (and using GET thereafter), you will need something like: if (isset($_POST['phone'])) { $phone = $_POST['phone']; } elseif (isset($_GET['phone']) { $phone = $_GET['phone']; } And you probably should consider some type of validation on the phone variable as well, unless you're certain that it won't be viewed by anyone except people in your own company.
  15. PHP Parse error: syntax error, unexpected '<script', expecting '<?php' in /usr/home/stradmadhu/original_post on line 1
  16. If you're sure that products *should* be found on a second page, have the script echo the values of $start and $perpage to you just before the query ... it may be that these values are not what you expect. Also, please consider using the [ code ] BB tags for your code
  17. Just a wild, wild guess ... scope issues. Are you really only loading it that way for the sake of brevity in the top-level document? What does your debugger tell you?
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.